Mapping enums : Cannot map final type

1,703 views
Skip to first unread message

Tomáš Bahník

unread,
Jun 23, 2017, 6:34:39 AM6/23/17
to modelmapper
Hello Mappers
when I try to map enum type (someone has decided to use int instead of string) I get 

org.modelmapper.ConfigurationException: ModelMapper configuration errors:

1) Cannot map final type x.y.z.enums.TerminalType.

1 error

at org.modelmapper.internal.Errors.throwConfigurationExceptionIfErrorsExist(Errors.java:241)
at org.modelmapper.internal.ExplicitMappingBuilder.visitPropertyMap(ExplicitMappingBuilder.java:229)
at org.modelmapper.PropertyMap.configure(PropertyMap.java:380)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)


public enum TerminalType {
   ABC("ABC", 1);

private String code;
private Integer intCode;

TerminalType(String code, Integer intCode,) {
this.code=code;
this.intCode = intCode;
}

map().setTerminalType(source.getTerminalType().getIntCode());

What's wrong with this?

Thanks

Tomas

Tomáš Bahník

unread,
Jun 23, 2017, 6:49:57 AM6/23/17
to modelmapper
I've noticed that there is error

org.modelmapper.internal.Errors#mappingForEnum but this is in case both S and D are enums.

No way to map from source enum type?

Dne pátek 23. června 2017 12:34:39 UTC+2 Tomáš Bahník napsal(a):

Tomáš Bahník

unread,
Jun 23, 2017, 7:26:47 AM6/23/17
to modelmapper
Could be solved by adding 

@Transient
public Integer getTerminalType()

to JPA Entity and leverage automated mapping, but the question remains.

Dne pátek 23. června 2017 12:34:39 UTC+2 Tomáš Bahník napsal(a):
Hello Mappers
Reply all
Reply to author
Forward
0 new messages