Frage

I have: _class A contains attributes: String userId, String a, String b. How can I use Dozer Mapping to map class A to class B (and otherwise) _class B has attributes: User user(object), String a, String b. _'User' is also a class whose id is userId Thanks for all help!

War es hilfreich?

Lösung

You can do like this , with the assumption your class A and B look like this :

 Class A{
 String userId;
 String a;
 String b;
 }

 Class B{
 User user;
 String a;
 String b;
 }

 Class User{
 String userId;
 }

You have add below mapping in your mapping ".xml" file.

   <mapping> 
      <class-a>com.techidiocy.example.A</class-a>
      <class-b>com.techidiocy.example.B</class-b>   
        <field>
           <a>userId</a>
           <b>user.userId</b>
        </field>
   </mapping>  
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top