Skip to content

Commit

Permalink
Ignore nulls by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Nov 30, 2017
1 parent d67e235 commit c3fb8b9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
@@ -1,3 +1,3 @@
# Version 1.0.0 (2017-09-??)
# Version 1.0.0 (2017-11-30)

* Initial commit.
* Initial release.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -23,7 +23,7 @@

<properties>
<seed.version>3.4.0</seed.version>
<business.version>4.0.0-SNAPSHOT</business.version>
<business.version>4.0.0</business.version>
<modelmapper.version>1.1.1</modelmapper.version>

<compatibility.skip>true</compatibility.skip>
Expand Down
Expand Up @@ -25,6 +25,7 @@ public class ModelMapperConfig {
private boolean ambiguityIgnored = false;
private boolean fullTypeMatchingRequired = false;
private boolean implicitMatching = true;
private boolean ignoreNulls = true;
private SourceConfig source = new SourceConfig();
private DestinationConfig destination = new DestinationConfig();

Expand Down Expand Up @@ -82,6 +83,15 @@ public ModelMapperConfig setImplicitMatching(boolean implicitMatching) {
return this;
}

public boolean isIgnoreNulls() {
return ignoreNulls;
}

public ModelMapperConfig setIgnoreNulls(boolean ignoreNulls) {
this.ignoreNulls = ignoreNulls;
return this;
}

public SourceConfig source() {
return source;
}
Expand Down
Expand Up @@ -9,6 +9,7 @@
package org.seedstack.business.modelmapper.internal;

import javax.inject.Provider;
import org.modelmapper.Conditions;
import org.modelmapper.ModelMapper;
import org.seedstack.business.modelmapper.ModelMapperConfig;
import org.seedstack.seed.Configuration;
Expand Down Expand Up @@ -39,6 +40,10 @@ public ModelMapper get() {
configuration.setDestinationNameTransformer(modelMapperConfig.destination().getNameTransformer());
configuration.setDestinationNamingConvention(modelMapperConfig.destination().getNamingConvention());

if (modelMapperConfig.isIgnoreNulls()) {
configuration.setPropertyCondition(Conditions.isNotNull());
}

return modelMapper;
}
}
Expand Up @@ -20,7 +20,6 @@
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.modelmapper.Conditions;
import org.modelmapper.PropertyMap;
import org.seedstack.business.assembler.Assembler;
import org.seedstack.business.assembler.DtoOf;
Expand Down Expand Up @@ -415,8 +414,6 @@ protected void configure(org.modelmapper.ModelMapper modelMapper) {
mapper.map(src -> src.getBillingAddress().getCity(), OrderDTO::setBillingCity);
});

modelMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull());

modelMapper.createTypeMap(OrderDTO.class, Order.class)
.addMappings(mapper -> {
mapper.<String>map(OrderDTO::getBillingCity, (dest, v) -> dest.getBillingAddress().setCity(v));
Expand Down

0 comments on commit c3fb8b9

Please sign in to comment.