i am trying to serialize an Hashmap of custom Objects on Android to get an xml like :
<ROWSET>
<ROW num="0">
<Name>foo</Name>
<FNAME>bar</FNAME>
<BIRTH>01/01/2000</BIRTH>
<Num>4376484</NUM>
</ROW>
<ROW num="1">
<Name>bar</Name>
<FNAME>foo</FNAME>
<BIRTH>02/02/2000</BIRTH>
<NUM>4376484</NUM>
</ROW>
</ROWSET>
I created an inner class that contains only the Hashmap that i'm interested in, as i was unable to serialize it the way it is (and read that it's not possible)
added an object to test like this listEval.put(0,currentEvaluation)
.
following, the inner class :
@Root (name="ROWSET")
public static class listOfEvals {
@ElementMap (entry="ROW", key="num", attribute=true, inline=true)
private Map<Integer, EvaluationContent> evalList;
public listOfEvals(Map<Integer, EvaluationContent> list){
evalList=list;
}
public Map<Integer, EvaluationContent> getEvalList() {
return evalList;
}
public void setEvalList(Map<Integer, EvaluationContent> evalList) {
this.evalList = evalList;
}
}
EvaluationContent object is defined like this :
public class EvaluationContent {
@Element(name="Name", required = false)
private String mName;
@Element(name="FNAME", required = false)
private String mFname;
@Element(name="BIRTH", required = false)
private String mBirth;
@Element(name="Num", required = false)
private String mNum;
public String getName() {
return mName;
}
public void setName(String mName) {
this.mName = mName;
}
...
}
The problem is that i'm getting a <evaluationContent>
tag for each entry:
<ROWSET>
<ROW num="0">
<evaluationContent>
<Name>foo</Name>
<FNAME>bar</FNAME>
<BIRTH>01/01/2000</BIRTH>
<Num>4376484</NUM>
</evaluationContent>
</ROW>
<ROW num="1">
<evaluationContent>
...
<evaluationContent>
</ROW>
</ROWSET>
There must be a better way to achieve that but i'm unable to figure out how, thanks for your help