Natural mapping with Enum to String

97 views
Skip to first unread message

vie...@yahoo.fr

unread,
Sep 29, 2016, 9:06:00 AM9/29/16
to Selma
Hello,

I'm starting to use Selma Mapping.

So far, so good, everything is working fine beside the compatibility with Lombok annotation (very useful for boiler plate code like getter setter ...) and a few time where I forgot to regenerate the mapper implementation.

Most of the time I'm using natural mapping (the attribute's name are the same).
I've recently tried to map an Enum to a String

Example :

public enum NumberEnum { ONE, TWO; }

public SourceBean {
   
private NumberEnum myNumber;
}

public DestinationBean {
   
private String myNumber;
}

Shouldn't the default behavior for the mapping be : the function name() ?

To get such behavior, I had to write a custom mapper :

public class EnumCustomMapper {
   
public String myNumberAsString(NumberEnum source) {
       
return source.name();
   
}
}


Is there an easier way ?

Cheers

HV

Reply all
Reply to author
Forward
0 new messages