Can't map property when using MapStruct

zygimantus picture zygimantus · Jan 8, 2016 · Viewed 17.5k times · Source

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?

Answer

zygimantus picture zygimantus · Jan 8, 2016

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)