orika-mapper / orika

Simpler, better and faster Java bean mapping framework
http://orika-mapper.github.io/orika-docs/
Apache License 2.0
1.29k stars 268 forks source link

Mapping java.util.Map attribute to java.util.HashMap throws MappingException #79

Open lorenet opened 9 years ago

lorenet commented 9 years ago

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;
                }

        }

}
ndr-brt commented 8 years ago

Will be fixed in 1.5.0

aduchate commented 6 years ago

Still not fixed in 1.5.2

hreichert commented 6 years ago

I can confirm that this issue is not fixed. The test case above still gives the same error message with 1.5.2

ghost commented 5 years ago

are there any plans to fix that ?