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

  • Home
  • SEARCH
  • 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 3346262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:16:58+00:00 2026-05-18T01:16:58+00:00

I need to map class A into class C using dozer framework. public class

  • 0

I need to map class A into class C using dozer framework.

public class A {

private String fielda1;
private String fielda2;

public String getFielda1() {
    return fielda1;
}
public void setFielda1(String fielda1) {
    this.fielda1 = fielda1;
}
public String getFielda2() {
    return fielda2;
}
public void setFielda2(String fielda2) {
    this.fielda2 = fielda2;
}
}


public class B {
private List<C> cList;

public List<C> getcList() {
    return cList;
}
public void setcList(List<C> cList) {
    this.cList = cList;
}

public static class C {
    private String fieldc1;
    private String fieldc2;

    public String getFieldc1() {
        return fieldc1;
    }
    public void setFieldc1(String fieldc1) {
        this.fieldc1 = fieldc1;
    }
    public String getFieldc2() {
        return fieldc2;
    }
    public void setFieldc2(String fieldc2) {
        this.fieldc2 = fieldc2;
    }
}
}

XML mapping file:

<mapping wildcard="false" map-null="false" map-id="test">
    <class-a>test.A</class-a>
    <class-b>test.B.C</class-b>
    <field>
        <a>fielda1</a>
        <b>fieldc1</b>
    </field>
    <field>
        <a>fielda1</a>
        <b>fieldc2</b>
    </field>
</mapping>

When i try to map these classes i got following exception:

org.dozer.MappingException: java.lang.ClassNotFoundException: test.B.C
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:88)
at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:33)

It seams that dozer is not capable to handle this situation and uses class B as a package name. This issue can be resolved using custom converters. I just want to know is there any trick that could be used to convert these classes using just XML configuration ?

  • 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-05-18T01:16:58+00:00Added an answer on May 18, 2026 at 1:16 am

    Try using test.B$C like in the following example:

    <mapping wildcard="false" map-null="false" map-id="test">
        <class-a>test.A</class-a>
        <class-b>test.B$C</class-b>
        <field>
            <a>fielda1</a>
            <b>fieldc1</b>
        </field>
        <field>
            <a>fielda2</a>
            <b>fieldc2</b>
        </field>
    </mapping>
    

    Also note that I changed the second field from fielda1 to fielda2, it appeared to be a typo in your example.

    Note: Because you set map-id="test" you must include mapId when you call map, like in:

    B.C destObject = mapper.map(a, B.C.class, "test");
    

    I tested and this is working correctly:

    A.java

    package com.test;
    
    public class A {
    
        private String fielda1;
        private String fielda2;
    
        public String getFielda1() {
            return fielda1;
        }
    
        public void setFielda1(String fielda1) {
            this.fielda1 = fielda1;
        }
    
        public String getFielda2() {
            return fielda2;
        }
    
        public void setFielda2(String fielda2) {
            this.fielda2 = fielda2;
        }
    }
    

    B.java

    package com.test;
    
    import java.util.List;
    
    public class B {
    
        private List<C> cList;
    
        public List<C> getcList() {
            return cList;
        }
    
        public void setcList(List<C> cList) {
            this.cList = cList;
        }
    
        public static class C {
    
            private String fieldc1;
            private String fieldc2;
    
            public String getFieldc1() {
                return fieldc1;
            }
    
            public void setFieldc1(String fieldc1) {
                this.fieldc1 = fieldc1;
            }
    
            public String getFieldc2() {
                return fieldc2;
            }
    
            public void setFieldc2(String fieldc2) {
                this.fieldc2 = fieldc2;
            }
        }
    }
    

    mapping.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <mappings xmlns="http://dozer.sourceforge.net" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
    
        <mapping wildcard="false" map-null="false" map-id="test">
            <class-a>com.test.A</class-a>
            <class-b>com.test.B$C</class-b>
            <field>
                <a>fielda1</a>
                <b>fieldc1</b>
            </field>
            <field>
                <a>fielda1</a>
                <b>fieldc2</b>
            </field>
        </mapping>
    
    </mappings>
    

    Main.java

    package com.test;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.dozer.DozerBeanMapper;
    import org.dozer.Mapper;
    
    public class Main5 {
    
        public static void main(String[] args) throws Exception {
            List<String> mappingFiles = new ArrayList<String>(1);
            mappingFiles.add("mapping.xml");
    
            Mapper mapper = new DozerBeanMapper(mappingFiles);
    
            A a = new A();
            a.setFielda1("fielda1Value");
            a.setFielda2("fielda2Value");
    
            B.C destObject = mapper.map(a, B.C.class, "test");
    
            System.out.println(destObject.getFieldc1());
            System.out.println(destObject.getFieldc2());
        }
    
    }
    

    This outputs in the console:

    ...
    fielda1Value
    fielda1Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I map a DataReader object into a class object by using generics?
I'm using python and I need to map locations like Bloomington, IN to GPS
In php, I often need to map a variable using an array ... but
I need to map two tables to a single class, having trouble figuring this
I have a map view with pins annotations into it. I need to pass
I need a 2d political map of the world on which I will draw
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I usually use C++ stdlib map whenever I need to store some data associated
I'd like to map the following sql in NHibernate. Will I need to make
I've got a windows forms map in a WindowsFormsHost, and I need it to

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.