I try to convert one complex object to another complex object. All the object have sub-object. In theses object, i have date with differents format...
Look at that :
ObjectA : {
Long dateA,
CustomObject: {
Long dateB
List<CustomObject2> myObject
}
}
CustomObject2 : {
Long dateC
}
And then my destination object :
ObjectB : {
LocalDateTime dateA,
CustomObject: {
LocalDateTime dateB
List<CustomObject3> myObject
}
}
CustomObject3 : {
LocalDateTime dateC
}
I have write mapstruct converter to convert ObjectA
to ObjectB
:
@Mapping( target = "dateA", qualifiedByName = "toLocalDateTime")
ObjectB convertROToBO(ObjectA in);
@Named("toLocalDateTime")
static LocalDateTime toLocalDate(final Long dateMilliseconds) {
if (dateMilliseconds == null) {
return null;
}
return Instant.ofEpochMilli(dateMilliseconds).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
So, when i convert my ObjectA
to ObjectB
, only my dateA
is converted (my dateB
@ dateC
are not converted).
*** How can i convert all my Long to LocalDateTime recursively with map struct ? Is it possible to do that with single converter and single convertion method ? ***
Thanks :)