Reputation: 633
I'm trying to make Dozer map my classes:
public class A {
private B someB;
private String someAText;
}
public class B {
private String someBText;
}
to a resulting Map.class
like the following:
"someAText" => "someATextValue"
"someBText" => "someBTextValue"
.
That is, I'm trying to specify nested class' field mapping to a flat Map
key destination. I'm using Dozer by Java API, not xml. I wasn't able to find appropriate builder configuration to manage this. Base code is something like:
beanMappingBuilder = new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(B.class, Map.class, TypeMappingOptions.oneWay(), mapNull(true));
mapping(A.class, Map.class, TypeMappingOptions.oneWay(), mapNull(true));
}
}
Upvotes: 2
Views: 585
Reputation: 131
I suggest you to try the following configuration:
beanMappingBuilder = new BeanMappingBuilder() {
@Override
protected void configure() {
// 'A > Map' mapping
mapping(A.class, Map.class, TypeMappingOptions.oneWay(), TypeMappingOptions.mapNull(true))
.fields("someAText", "someATextValue")
.fields("someB.someBText", "someBTextValue");
// 'B > Map' mapping
mapping(B.class, Map.class, TypeMappingOptions.oneWay(), TypeMappingOptions.mapNull(true))
.fields("someBText", "someBTextValue");
}
}
Upvotes: 0