Reputation: 198
I have a problem . I am using Dozer for mapping data in spring and hiberante but when using mapping , maps null to variables of modelview class.
Please help me.
This is Controller.java
@GetMapping("/getTraffic/{id}")
public List getTrafficByEmpNo(@PathVariable(value = "id") Float empNo){
return Dozer.mapList(dateFileService.getPersonTraffic(empNo),DataFileViewModel.class);
}
This is Dozer.java
public static <S, D> List<D> mapList(List<S> sourceList, Class<D> destinationClass) {
List<D> destionationList = new ArrayList<>();
for (S source : sourceList) {
if (source != null) {
destionationList.add(getMapper(destinationClass).map(source, destinationClass));
}
}
return destionationList;
}
private static <D> DozerBeanMapper getMapper(Class<D> destinationClass){
DozerBeanMapper mapper = new DozerBeanMapper();
String packaging = destinationClass.getSimpleName();
if (!packaging.contains("ViewModel")) {
mapper.setMappingFiles(Arrays.asList("dozer/"+packaging.toLowerCase()+"/"+packaging.toLowerCase()+".xml"));
} else {
String classDozer = packaging.substring(0,packaging.indexOf("ViewModel")).toLowerCase();
mapper.setMappingFiles(Arrays.asList("dozer/"+classDozer+"/"+classDozer+".xml"));
}
return mapper;
}
this is dozer.xml
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping>
<class-a>org.sap.model.DataFile</class-a>
<class-b>org.sap.web.viewModel.DataFile.DataFileViewModel</class-b>
</mapping>
</mappings>
Upvotes: 0
Views: 185