Suppose I have a source object, containing two properties, a and b like this:
public class Source {
String a, b;
}
and a target object with one property c:
public class Target {
String c;
}
I'd like to define a mapping that will:
I thought it would be possible with a mapper with mapNulls set to false:
factory.registerClassMap(factory.classMap(Source.class, Target.class).field("a", "c").field("b", "c").mapNulls(false));
However, when I set property a to a non-null value and leave property b to null, the mapping results in a target object with c set to null.
Have I misunderstood the purpose of mapNulls?
It's because mapNulls
set the property at the last field. Try setting at both fields.
You can implement a ConfigurableMapper
too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.