I am using MapStruct library to map objects but I got this error:
Can't map property "java.util.Date aDate" to "javax.xml.bind.JAXBElement ADATE". Consider to declare/implement a mapping method: "javax.xml.bind.JAXBElement map(java.util.Date value)".
My question: WHERE should I decleare this mapping method?
We can ignore unmapped properties in several mappers by setting the unmappedTargetPolicy via @MapperConfig to share a setting across several mappers. We should note that this is a simple example showing the minimal usage of @MapperConfig, which might not seem much better than setting the policy on each mapper.
Annotation Type MappingTargetDeclares a parameter of a mapping method to be the target of the mapping. Not more than one parameter can be declared as MappingTarget . NOTE: The parameter passed as a mapping target must not be null .
edited. mapstruct in combination with Lombok, is unable to correctly resolve mappings specified as property fields only, when correctly annotated with Lombok annotations @DaTa or more verbosely using @Setter and @getter only. Except getters and setter are also provided to the source and target classes.
During compilation, MapStruct will generate an implementation of this interface. This implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection or similar.
I solved this issue by writing another class:
public class DateMapper {
public JAXBElement<XMLGregorianCalendar> map(Date value) {
// conversion here
return atswer;
}
}
and using this annotation:
@Mapper(uses=DateMapper.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With