atos1990 / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Orika maps enum to enum, but not List<enum> to List<enum> #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This test class will succeed:

-------------------------------------------------------
package test.orika;

import static org.junit.Assert.assertEquals;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

import org.junit.Test;

public class EnumMapTest {

    @Test
    public void testEnumMap() {
        final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        final MapperFacade mapper = mapperFactory.getMapperFacade();

        final A a = new A();
        a.setMyEnum(MyEnum.foo);
        final A2 a2 = mapper.map(a, A2.class);

        assertEquals(MyEnum2.foo, a2.getMyEnum());
    }

    public static enum MyEnum {
        foo, bar
    }

    public static class A {
        private MyEnum  myEnum;

        public MyEnum getMyEnum() {
            return myEnum;
        }

        public void setMyEnum(final MyEnum myEnum) {
            this.myEnum = myEnum;
        }
    }

    public static enum MyEnum2 {
        foo, bar
    }

    public static class A2 {
        private MyEnum2 myEnum;

        public MyEnum2 getMyEnum() {
            return myEnum;
        }

        public void setMyEnum(final MyEnum2 myEnum) {
            this.myEnum = myEnum;
        }
    }
}
-------------------------------------------------------

This one will fail with the error
 ma.glasnost.orika.MappingException: While attempting the folling mapping:
 sourceType = MyEnum
 destinationType = MyEnum2

-------------------------------------------------------
package test.orika;

import java.util.ArrayList;
import java.util.List;

import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

import org.junit.Test;

public class EnumListMapTest {

    @Test
    public void testEnumListMap() {
        final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        final MapperFacade mapper = mapperFactory.getMapperFacade();

        final A a = new A();
        final List<MyEnum> myEnumList = new ArrayList<MyEnum>();
        myEnumList.add(MyEnum.foo);
        a.setMyEnum(myEnumList);
        mapper.map(a, A2.class);

    }

    public static enum MyEnum {
        foo, bar
    }

    public static class A {
        private List<MyEnum>    myEnum;

        public List<MyEnum> getMyEnum() {
            return myEnum;
        }

        public void setMyEnum(final List<MyEnum> myEnum) {
            this.myEnum = myEnum;
        }
    }

    public static enum MyEnum2 {
        foo, bar
    }

    public static class A2 {
        private List<MyEnum2>   myEnum;

        public List<MyEnum2> getMyEnum() {
            return myEnum;
        }

        public void setMyEnum(final List<MyEnum2> myEnum) {
            this.myEnum = myEnum;
        }
    }
}
-------------------------------------------------------

If orika is able to map MyEnum to MyEnum2 it should be able to map it inside a 
List too. After all it is able to detect the destination type correctly.

Using orika 1.3.5.

Original issue reported on code.google.com by wirch.ed...@gmail.com on 21 Nov 2012 at 2:58

GoogleCodeExporter commented 9 years ago

Original comment by elaat...@gmail.com on 21 Nov 2012 at 4:18

GoogleCodeExporter commented 9 years ago
Fix has been applied to current master.

Original comment by matt.deb...@gmail.com on 24 Nov 2012 at 6:31

GoogleCodeExporter commented 9 years ago
Fixed in 1.4.0 release

Original comment by matt.deb...@gmail.com on 19 Dec 2012 at 1:59