If any source property is null or empty just skip

4,563 views
Skip to first unread message

DK

unread,
May 25, 2015, 7:07:57 AM5/25/15
to model...@googlegroups.com
Hi,

I want to setup a ModelMapper that will map source and target Objects of the same class e.g. both target and source are type MyPoJo

Is there any easy way to configure the Mapper so that : "If any source property is null or empty just skip"

At the moment I have to do this for every field 
when(Conditions.or(isNull, isEmpty)).skip().setFieldOne(null);
when(Conditions.or(isNull, isEmpty)).skip().setFieldTwo(null);
when(Conditions.or(isNull, isEmpty)).skip().setFieldThree(null);

Jonathan Halterman

unread,
May 25, 2015, 12:33:00 PM5/25/15
to model...@googlegroups.com
You have two more options - one is to set your conditions on a particular TypeMap, which will apply it to all properties on the mapped types:

modelMapper.getTypeMap(Foo.class, Bar.class).setPropertyCondition(condition);

The other is to set your condition globally, which will apply for all properties:

modelMapper.getConfiguration().setPropertyCondition(condition);

- jonathan

--
You received this message because you are subscribed to the Google Groups "modelmapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modelmapper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yayat...@gmail.com

unread,
May 29, 2015, 8:32:06 PM5/29/15
to model...@googlegroups.com
Hi,

I don't see this method setPropertyCondition() in the Configuration interface, I am on 0.7.4 version. Which version has this?

modelMapper.getConfiguration().setPropertyCondition(condition);

Thanks

Jonathan Halterman

unread,
May 29, 2015, 8:35:10 PM5/29/15
to model...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages