Can't map property when using MapStruct

折月煮酒 提交于 2019-12-10 16:45:59

问题


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?


回答1:


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)



回答2:


There are two alternatives:

  • Make your mapper an abstract class instead of an interface and implement that method directly in the mapper class
  • Implement the method on another class and declare this one as "used" by your mapper; See the reference guide for further details

Btw. the mapping should be done automatically if you are using XMLGregorianCalendar or JAXBElement<XMLGregorianCalendar> instead of the JAXBElement raw type.



来源:https://stackoverflow.com/questions/34672216/cant-map-property-when-using-mapstruct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!