java - why DozerConverter is not working? -
i using dozer version 5.5.1. , want configure custom converter have this
import org.dozer.dozerconverter; import com.example.movies.api.models.response.clientresponsedto; public class mycustomconverter extends dozerconverter<clientresponsedto, string> { public mycustomconverter() { super(clientresponsedto.class, string.class); } @override public string convertto(clientresponsedto source, string destination) { return "clientresponsedto converted string!"; } @override public clientresponsedto convertfrom(string source, clientresponsedto destination) { return new clientresponsedto(); } }
which loading spring this:
@bean public mapper dozerbeanmapper() { dozerbeanmapper mapper = new dozerbeanmapper(); list<customconverter> converters = new arraylist<>(); converters.add(new mycustomconverter(clientresponsedto.class, string.class)); mapper.setcustomconverters(converters); return mapper; }
then, have usage:
@autowired mapper mapper; ... clientresponsedto clientresponsedto = clientservice.getclient(id); string conversion = this.mapper.map(clientresponsedto, string.class);
and custom converter never being called. know why ? regards!
refer dozer documenttion should add mapping bean description. eg.
<bean id="org.dozer.mapper" class="org.dozer.dozerbeanmapper"> <property name="mappingfiles"> <list> <value>systempropertymapping1.xml</value> <value>dozerbeanmapping.xml</value> <value>injectedcustomconverter.xml</value> </list> </property><property name="customconverterswithid"> <map> <entry key="customconverterwithid" ref="configurableconverterbeaninstance1" /> <entry key="customconverterwithid2" ref="configurableconverterbeaninstance2" /> </map> </property> </bean>