How would you map a class with generic fields?

52 views
Skip to first unread message

sebastien...@gmail.com

unread,
Nov 5, 2015, 8:50:40 AM11/5/15
to Selma
How would you map the StringContainer class bellow?

public class Container<T> {
 
private List<T> elements;


 
public List<T> getElements() {
 
return elements;
 
}


 
public void setElements(List<T> elements) {
 
this.elements = elements;
 
}
}


public class StringContainer extends Container<String> {


}

As-is, Selma mapper does not compiler (T cannot be resolved to a type):

  public final selmatest1.b.StringContainer asStringContainer(selmatest1.a.StringContainer in) {
    selmatest1
.b.StringContainer out = null;
   
if (in != null) {
     
out = new selmatest1.b.StringContainer();
     
if (in.getElements() != null) {
        java
.util.ArrayList<T> aelementsTmpCollection = new java.util.ArrayList<T>(in.getElements().size());
       
out.setElements(aelementsTmpCollection);
       
for (T aelementsItem : in.getElements()) {
       
}
     
}
     
else {
       
out.setElements(null);
     
}
   
}
   
return out;
 
}

Manually mapping the whole StringContainer is not an option, as it contains a lot of fields. An acceptable workaround would be the ability to manually map the elements field, but I understand this currently is not possible.
Reply all
Reply to author
Forward
0 new messages