how to exclude whole property if they are null from Modelmapper

Clash Royale CLAN TAG#URR8PPPhow to exclude whole property if they are null from Modelmapper
Does ModelMapper(http://modelmapper.org/) support what exclude property? If the value is null.
I just found PropertyMap out. but It is a constraint to me.
because I have to describe a specific property that I want.
Like this.
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<TestObject, TestObject>() {
@Override
protected void configure() {
when(Conditions.isNull()).skip().setName(source.getName());
when(Conditions.isNull()).skip().set...(source.get...());
when(Conditions.isNull()).skip().set...(source.get...());
when(Conditions.isNull()).skip().set...(source.get...());
when(Conditions.isNull()).skip().set...(source.get...());
when(Conditions.isNull()).skip().set...(source.get...());
}
});
In my case, I have a lot of property and verbose.
How to exclude mapping property if they are null from all them.
Is there more comfortable solution?
thanks.
2 Answers
2
You can configure ModelMapper to ignore all properties that are null with the following configuration:
modelMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull());
It is useful, for example, for partial updates of a target object where you only want to copy those properties from the source object that are not null.
Regarding the selected answer above, Is it the case when I want to map my destination object, which already has properties with values, with the source object that has the same properties which are null, and at the return, I will get object's properties with the same values, but definitely not null ?!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks, That's I wanted.
– Brady
May 14 at 7:03