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 8617703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:55:32+00:00 2026-06-12T05:55:32+00:00

Suppose I have following Class – structure ? class A{ List<B> listB; //getter and

  • 0

Suppose I have following Class – structure ?

class A{
List<B> listB;
//getter and setter
}
class B{
String s;
//getter and setter
}
//objectOfA has listB = [null,objectOfB,null]
A a2 = dozermapper.map(objectOfA,A.class);

I want a2 contains listB=[objectOfB] only. not null elements of list.

How to do it in dozer?

  • 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-12T05:55:33+00:00Added an answer on June 12, 2026 at 5:55 am

    You could write a simple converter, like this (uses new converter api, you can use old also):

    public class Converter extends DozerConverter<List<B>, List<B>> {
      public Converter() {
        super(List.class, List.class);
      }
    
      public List<B> convertTo(List<B> source, List<B> destination) {
        List<B> result = new ArrayList<B>();
        for (B item : source) {
          if (item != null) {
              result.add(item); //or item copy, or whatever you want
          }
        }
        return result;
      }
    } 
    

    and then attach it to your mapping like this:

    <mapping>
      <class-a>yourpackage.A</class-a>
      <class-b>yourpackage.A</class-b>    
      <field custom-converter="yourpackage.Converter">
          <a>listB</a>
          <b>listB</b>
      </field>
    </mapping> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following: public class MyObject { public string Name {get; set;}
Suppose I have the following types of data: class Customer { String id; //
Suppose I have the following class structure: [XmlInclude(typeof(CustomNode))] [XmlInclude(typeof(CustomNode2))] [XmlRoot(node)] class Node { [XmlElement(node)]
Suppose I have the following class SimpleClass (myInt: Int, myString: String) { } What
Suppose I have the following class: public class Foo { private List<Integer> list =
Suppose you have following class: class ProcessController { public List<Process> Active { get {
Suppose I have the following class structure: public class State { public int Id
Suppose I have the following classes: public class Test { public static void main(String[]
Suppose I have the following class: public class Test{ public string Length { get;
Suppose you have the following class: class Test : ISerializable { public static Test

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.