Mapping a java.util.Map attribute to a java.util.HashMap one throws a MappingException:
Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.HashMap
at ma.glasnost.orika.generated.Orika_Destination_Source_Mapper32463485991091$0.mapAtoB(Orika_Destination_Source_Mapper32463485991091$0.java)
at ma.glasnost.orika.impl.mapping.strategy.UseCustomMapperStrategy.map(UseCustomMapperStrategy.java:67)
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:742)
... 25 more
Used Version: 1.4.6
Test Case:
import java.util.HashMap;
import java.util.Map;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.junit.Assert;
import org.junit.Test;
public class IssueMapToHashMapTest {
@Test
public void mapTest() {
try {
final MapperFactory mapperFactory = new DefaultMapperFactory.Builder()
.build();
Source input = new Source();
Map<String, String> map = new HashMap<String, String>();
map.put("key_1", "value_1");
map.put("key_2", "value_2");
input.setMap(map);
Destination output = mapperFactory.getMapperFacade().map(input,
Destination.class);
Assert.assertNotNull(output);
Assert.assertNotNull(output.getMap());
Assert.assertTrue(output.getMap().size() > 0);
Assert.assertTrue(output.getMap().get("key_1").equals("value_1"));
Assert.assertTrue(output.getMap().get("key_2").equals("value_2"));
} catch (Throwable th) {
System.err.println(th.toString());
th.printStackTrace();
Assert.fail(th.toString());
}
}
public static class Source {
private Map<String, String> map;
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> mappa) {
this.map = mappa;
}
}
public static class Destination {
private HashMap<String, String> map;
public HashMap<String, String> getMap() {
return map;
}
public void setMap(HashMap<String, String> mappa) {
this.map = mappa;
}
}
}
Mapping a java.util.Map attribute to a java.util.HashMap one throws a MappingException:
Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.HashMap at ma.glasnost.orika.generated.Orika_Destination_Source_Mapper32463485991091$0.mapAtoB(Orika_Destination_Source_Mapper32463485991091$0.java) at ma.glasnost.orika.impl.mapping.strategy.UseCustomMapperStrategy.map(UseCustomMapperStrategy.java:67) at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:742) ... 25 more
Used Version: 1.4.6
Test Case: