Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not converter source list to destination list with same enum property #382

Open
steelcg opened this issue Oct 19, 2021 · 0 comments
Open

Comments

@steelcg
Copy link

steelcg commented Oct 19, 2021

enum:

public enum YNEnum {
    Y,
    N
}

source type:

public class KeyValuePO {
    private Integer key;
    private String value;
    private YNEnum ynEnum;
...

destination type:

public class KeyValueVO {
    private Integer key;
    private String value;
    private YNEnum ynEnum;
...

converter code

   public static <S, D> List<D> getDeeplyCopiedObject(List<S> source, Class<D> destinationType) {
        Assert.notNull(source, "Source must not be null");
        Assert.notNull(destinationType, "Destination Type Type must not be null");
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        mapperFactory.classMap(source.getClass(), destinationType).byDefault().register();
        MapperFacade mapper = mapperFactory.getMapperFacade();
        return mapper.mapAsList(source, destinationType);
    }

and the invoke code

        List<KeyValuePO> keyValues = new ArrayList<>();
        keyValues.add(new KeyValuePO(1, "v1", YNEnum.Y));
        keyValues.add(new KeyValuePO(2, "V2", YNEnum.N));
        List<KeyValueVO> deeplyCopiedObject = ObjectUtil.getDeeplyCopiedObject(keyValues, KeyValueVO.class);

then we get the error:

13:40:27.036 [main] DEBUG ma.glasnost.orika.metadata.ClassMapBuilder - ClassMap created:
	ClassMapBuilderForLists.map(ArrayList<Object>, KeyValueVO)
	 .field( 1(Object), key(Integer) )
	 .field( 2(Object), value(String) )
	 .field( 3(Object), ynEnum(YNEnum) )
Disconnected from the target VM, address: '127.0.0.1:59176', transport: 'socket'
14:01:15.316 [main] DEBUG ma.glasnost.orika.impl.generator.MapperGenerator - Generating new mapper for (ArrayList<Object>, KeyValueVO)
	Orika_KeyValueVO_ArrayList_Mapper525728805489300$0.mapAToB(ArrayList<Object>, KeyValueVO) {
	 Field(1(Object), key(Integer)) : mapping multi-occurrence element of type Object to object
	 Field(2(Object), value(String)) : converting using builtin:ToStringConverter<Object, Object>
<---- ERROR occurred here

ma.glasnost.orika.MappingException: ma.glasnost.orika.MappingException: While attempting the following mapping:
sourceType = java.util.ArrayList<Object>
sourceProperty = 3(Object)
destinationType = ...KeyValueVO
destinationProperty = ynEnum(YNEnum)
Error occurred: ma.glasnost.orika.MappingException: Encountered mapping of enum to object (or vise-versa); sourceType=Object, destinationType=YNEnum

	at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:104)
	at ma.glasnost.orika.impl.DefaultMapperFactory.buildMapper(DefaultMapperFactory.java:1478)
	at ma.glasnost.orika.impl.DefaultMapperFactory.build(DefaultMapperFactory.java:1293)
	at ma.glasnost.orika.impl.DefaultMapperFactory.getMapperFacade(DefaultMapperFactory.java:881)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant