Here is a good example of how to map a list of elements to Map using Orika
Is it possible to convert a List to a Map using Orika?
-
25-06-2022 - |
Вопрос
I am looking convert a List of custom objects to a Map of custom objects. I have a mapping defined with a custom method, but I keep getting a "cannot be cast to ma.glasnost.orika.MapEntry" exception. What is the proper way to go about converting a List to a Map in Orika?
mapperFactory.classMap(new TypeBuilder<List<com.printable.pti.NameValuePairType>>(){}.build(), new TypeBuilder<Map<String, com.kinetic.entity.TemplateField>>() {}.build())
.customize(new CustomMapper<List<com.printable.pti.NameValuePairType>,Map<String, com.kinetic.entity.TemplateField>>() {
@Override
public void mapAtoB(List<com.printable.pti.NameValuePairType> nameValuePairTypes,
Map<String, com.kinetic.entity.TemplateField> stringTemplateFieldMap, MappingContext context) {
Map<String, com.kinetic.entity.TemplateField> toObject = new HashMap<String, com.kinetic.entity.TemplateField>();
for(com.printable.pti.NameValuePairType nameValuePairType : nameValuePairTypes) {
toObject.put(nameValuePairType.getName(),(com.kinetic.entity.TemplateField)map(nameValuePairType,com.kinetic.entity.TemplateField.class));
}
}
}
)
.register();
Решение
Не связан с StackOverflow