jmapper-core
jmapper-core copied to clipboard
Default value
Allowing the definition of default values. These values are used only in case of source fields nulls.
hi there, is there any progress on this because we need it urgently? Thanks
sorry @martin3361, i'm working on immutable objects now and as next step i want to review all XML/API exception, my scope is consolidate everything done so far and then resume with developments.
here's what I propose as a temporary solution:
- enrich the constructor of your bean with default values
public class Destination {
String field;
public Destination(){
this.field = "default value";
}
}
or use get/set methods after creation, and as second step using this strategy:
JMapper<Destination, Source> mapper = new JMapper<>(Destination.class, Source.class);
Destination destination = new Destination();
Source source = ....
destination = mapper.getDestination(destination, source, MappingType.ALL_FIELDS, MappingType.ONLY_VALUED_FIELDS);
In this mode the values of Destination are overridden only when source fields are valorized.
I hope I was helpful
Thanks for the prompt input! I already had taken this approach, thanks for confirming this