Search code examples
javamappingdozer

Dozer Mapping from string to Object


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!


Solution

  • 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>