jmapper-core icon indicating copy to clipboard operation
jmapper-core copied to clipboard

Default value

Open avurro opened this issue 9 years ago • 3 comments

Allowing the definition of default values. These values are used only in case of source fields nulls.

avurro avatar Jun 20 '16 19:06 avurro

hi there, is there any progress on this because we need it urgently? Thanks

martin3361 avatar Aug 11 '16 07:08 martin3361

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

avurro avatar Aug 11 '16 08:08 avurro

Thanks for the prompt input! I already had taken this approach, thanks for confirming this

martin3361 avatar Aug 11 '16 08:08 martin3361