简体   繁体   中英

Dozer Mapping between primitive datatype and Custom object?

I have the following scenario :

Class A{
  private List<Long> longList;
  //getter and setter
}

Class B{
  private List<C> listC;
  //getter and setter
}

Class C{
  private Long id;
  //getter and setter
}

Now, I want to convert between longList and C . I found the following mapping :

<mapping>
  <class-a>A</class-a>
  <class-b>B</class-b>
  <field>
    <a>longList</a>
    <b>listC</b>
    <a-hint>java.lang.Long</a-hint>
    <b-hint>C</b-hint>
  </field>
</mapping>

I am not sure whether the above mapping is the proper solution or not. Can I set up a mapping between long and C , such that long gets mapped to C.id ?

You could try mapping Long to C like so:

<mapping>
    <class-a>A</class-a>
    <class-b>B</class-b>
    <field>
        <a>longList</a>
        <b>listC</b>
    <field>
</mapping>

<mapping>
    <class-a>java.lang.Long</class-a>
    <class-b>C</class-b>
    <field>
        <a>this</a>
        <b>id</b>
    <field>
</mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM