publicissapient-france / selma

Selma Java bean mapping that compiles
http://selma-java.org
Apache License 2.0
213 stars 38 forks source link

Does it support immutable classes #62

Open mozinrat opened 9 years ago

mozinrat commented 9 years ago

Does the mapper support immutable classes, in absence of setter use constructor. If yes can you share an example

slemesle commented 9 years ago

No Selma does not map on constructor fields. The base code use properties to properties and type to type mapping, but it does not try to map properties by constructor it seems like a hard thing to automate. The only way I see to support it would be to force a strong convention on constructor parameter names or describe each arguments with annotations.

If you have any clues how to do it smartly, this issue is a good place to talk about it.

mozinrat commented 9 years ago

A simple mapping strategy with annotation targeted for immutable classes looks good to me. Consider a immutable class the no. of arguments will match the no. go getter of properties. The idea is to use getters to figure out property mapping. Primitive not defined should set to default initialisation, objects should be null if no mapping found.

something like @ImmutableMapping({ @Mapping(source ="rhs.prop1" target="lhs.prop2")})

The mapping should be focused on below class mapping LHS map(RHS rhs)

Class LHS{ prop1, prop

constructor(prop1, prop2) }

Class RHS{ prop2, prop // will have getters for sure }

Type mapping and typecasting again leverage return type of getters in Immutable class. This seems a vague idea, I will give it a thought and figure out how to make it more usable for community.

pjean commented 8 years ago

:+1: for immutable classes support