Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:00:22+00:00 2026-06-05T10:00:22+00:00

In first class i have field: private Set<Country> countries; public Set<Country> getCountries() { return

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:00:24+00:00Added an answer on June 5, 2026 at 10:00 am

    When Dozer maps a Set, it uses the org.dozer.util.CollectionUtils.createNewSet to create the destination Set instance. You get either a HashSet or TreeSet.

    If the order of your elements is the same as their natural order you might use a SortedSet in the destination. If not, then you need to create the destination object yourself and provide the desired Set implementation.

    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:

    public class MyInstanceCreator {
        public static DestinationObject createDestinationObject() {
            DestinationObject result = new DestinationObject();
            result.setCountries(new LinkedHashSet<Country>());
            return result;
        }
        private MyInstanceCreator() { }
    }
    

    mapping:

    <mapping>
        <class-a create-method="MyInstanceCreator.createDestinationObject">DestinationObject</class-a>
        <class-b>SourceObject</class-b>
        <field>
            <a>countries</a>
            <b>countries</b>
        </field>
    </mapping>
    

    Bean factory

    Java code:

    public class MyBeanFactory implements BeanFactory {
        public Object createBean(Object source, Class<?> sourceClass, String targetBeanId) {
            DestinationObject result = new DestinationObject();
            result.setCountries(new LinkedHashSet<Country>());
            return result;
        }
    }
    

    mapping:

    <mapping>
        <class-a bean-factory="MyBeanFactory">DestinationObject</class-a>
        <class-b>SourceObject</class-b>
        <field>
            <a>countries</a>
            <b>countries</b>
        </field>
    </mapping>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this middleware which is the first: class RedirectIt require net/https require uri
my code is like this: i have two classes first class: public class Box<E>
I have two classes, first: public class A { public delegate void Function(); public
I have a web application and two class files, First class is MyClass.class which
I have this application with 2 classes, in the first class I define a
Using Dozer to map two objects, I have: /** /* This first class uses
I have a class like Quete (first in , first out) public class Tor<T>
Lets say I have two similar class: public class First { public static final
I have a Java problem with nested classes. My first class structure looked like
I have a .py file with lots of classes: class First(Second): #code class Third(Fourth):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.