I have collection of StateTax and LocalTax in SrcObject. This need to be mapped to a collection of StateLocalTax. In SrcObject if i have three SrcStateTax and two SrcLocalTax, I would like to map these to a collection of StateLocalTax which will have four element. Three element of this collection would contain stateTax info with null destLocalTaxGroup and one element would contain collection of destLocalTaxGroup having two LocalTax info.
public class SrcObject {
private List<SrcStateTax> srcStateTaxGroup;
private List<SrcLocalTax> srcLocalTaxGroup;
//Getter setter
}
public class SrcStateTax {
private String srcStateCode;
private String srcStateTaxAmount;
……
//Getter setter
}
public class SrcLocalTax {
private String srcLocalCode;
private String srcLocalTaxAmt;
……
//Getter setter
}
Target Object is
public class DestObject {
private List<StateLocalTax> stateLocalTaxGroup;
……..
//Getter setter
}
public class StateLocalTax {
private String destStateCode;
private String destStateTaxAmount;
…….
private List<DestLocalTax> destLocalTaxGroup;
//Getter setter
}
public class DestLocalTax {
private String destLocalCode;
private String destLocalTaxAmt;
}
Dozer Mapping:
<mapping>
……….
<field map-id="map-StateTax">
<a>srcStateTaxGroup</a>
<b>stateLocalTaxGroup</b>
<a-hint>com.sample.source.SrcStateTax</a-hint>
<b-hint>com.sample.target.StateLocalTax</b-hint>
</field>
<field map-id="map-LocalTax">
<a>srcLocalTaxGroup</a>
<b>stateLocalTaxGroup.destLocalTaxGroup </b>
<a-hint>com.sample.source.SrcLocalTax</a-hint>
<b-hint>com.sample.target.DestLocalTax</b-hint>
</field>
</mapping>
<mapping map-id="map-StateTax">
<class-a>com.sample.source.SrcStateTax</class-a>
<class-b>com.sample.target.StateLocalTax</class-b>
<field>
<a>srcStateCode</a>
<b>destStateCode</b>
</field>
<field>
<a>srcStateTaxAmount</a>
<b>destStateTaxAmount</b>
</field>
</mapping>
<mapping map-id="map-1099RLocalTaxGroups">
<class-a>com.sample.source.SrcLocalTax</class-a>
<class-b>com.sample.target.DestLocalTax</class-b>
<field>
<a>srcLocalCode</a>
<b>destLocalCode</b>
</field>
<field>
<a>srcLocalTaxAmt</a>
<b>destLocalTaxAmt</b>
</field>
</mapping>
I'm rightly getting an error "No read or write method found for field (stateLocalTaxGroup.destLocalTaxGroup) in class ..
but not sure how to address this use case.
Your first dozer mapping has the following:
stateLocalTaxGroup is a List object. You cannot directly access "destLocalTaxGroup" from it, hence the error: No read or write method found for field (stateLocalTaxGroup.destLocalTaxGroup). It is saying there is no getter/setter in your list object which is correct.
The shortest way to resolve your issue would be to move
To your Destination Object so both have the same hierarchy.