java - Orika Mapping nested multi-occurrence elements -


i want map persons (mens , womens) same persondto orika.

class name {    private string first;    private string last;    private string fullname;    // getters/setters  }  class womens{    private list<name> names;    // getters/setters  }  class mens{    private list<name> names;    // getters/setters  }  class person {    private mens mens;    private womens womens;    // getters/setters  }  class persondto {    private list<info> info;   // getters/setters omitted }  class info {    private string notes;   // getters/setters omitted } 

if test mens only, ok.

mapperfactory.classmap(person.class, persondto.class)        .field("mens.names{first}", "info[0].notes")        .field("mens.names{last}", "info[1].notes")        .field("mens.names{fullname}", "info[2].notes")        .register(); 

if test womens only, ok,

mapperfactory.classmap(person.class, persondto.class)        .field("womens.names{first}", "info[0].notes")        .field("womens.names{last}", "info[1].notes")        .field("womens.names{fullname}", "info[2].notes")        .register(); 

but if test mens , womens, ko. info array not have size

mapperfactory.classmap(person.class, persondto.class)        .field("mens.names{first}", "info[0].notes")        .field("mens.names{last}", "info[1].notes")        .field("mens.names{fullname}", "info[2].notes")        .field("womens.names{first}", "info[3].notes")        .field("womens.names{last}", "info[4].notes")        .field("womens.names{fullname}", "info[5].notes")        .register(); 

i find solution not best. have better respons, please post here solution.

i split 2 infomaton class:

@xmlrootelement(name = "notes") class infomen {      private string notes;     // getters/setters omitted }  @xmlrootelement(name = "notes") class infowomen {      private string notes;     // getters/setters omitted }  @xmlrootelement(name = "persons") class persondto {      private list<infomen> infomen;     private list<infowomen> infowomen;      @xmlelement(name = "notes")     public list<infomen> getinfomen() {         return infomen;     }      @xmlelement(name = "notes")     public list<infowomen> getinfowomen() {         return infowomen;     }     // setters omitted } 

my xml output ok persondto object contains 2 objects instand of one.

<persons>     <notes>         <first>petter</first>         <last>butter</last>         <fullname>petter butter<fullname>     </notes>     <notes>         <first>wenddy</first>         <last>window</last>         <fullname>wenddy window<fullname>     </notes> </persons> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -