Using Dozer how to copy the collection inside a java object but skipping the object itself

StackOverflow https://stackoverflow.com/questions/19777245

  •  03-07-2022
  •  | 
  •  

Question

I have source class hierarchy as below

Class A {
    List<B> bs;
}

Class B {
    List<C> cs;
}

Class C {
   String n;
}

The new destination class hierarchy is as below

Class A1 {
    List<C1> cs;
}


Class C1 {
    String n;
}

As you can see the destination class hierarchy is skipping bs. How to configure this copying of a property in the object to the destination but skipping the object itself in the source

Était-ce utile?

La solution

One crude solution is to pre-process the source and copy the List<C> cs to a transient variable in Class A. The source will look like this after the pre-process

Class A {
    List<B> bs;

    transient List<C> cs;
}

Class B {
   List<C> cs;
}

Class C {
   String n; 
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top