In first class i have field:
private Set<Country> countries;
public Set<Country> getCountries() {
return countries;
}
public void setCountries(Set<Country> countries) {
this.countries = countries;
}
which will contain LinkedHashSet implementation.
In second class i have identical declaration, but during mapping, Dozer creates HashSet implementation in destination class, which destroys the order of elements. How to tell Dozer to use LinkedHashSet in destination class?
When Dozer maps a
Set, it uses theorg.dozer.util.CollectionUtils.createNewSetto create the destinationSetinstance. You get either aHashSetorTreeSet.If the order of your elements is the same as their natural order you might use a
SortedSetin the destination. If not, then you need to create the destination object yourself and provide the desiredSetimplementation.Dozer allows using custom create methods or custom bean factories to instantiate objects beyond using the default constructor so you could use either method:
Create method
Java code:
mapping:
Bean factory
Java code:
mapping: