I would like use this method:
json.add("myText", getList(id));
The function getList(id) return an arraylist, but the method json.add would like a JsonElement.
So, how can i cast an arraylist in JsonElement ?
I test this, but it doesn’t work:
json.add("myText", (JsonElement)getList(id));
I test this too:
JsonElement jelement = new JsonElement() {
private ArrayList<String> list= new ArrayList<String>(); public ArrayList<String> getList(){ return this.list; }};
com.google.gson has methods for serializing an ArrayList (or any collection). Once you have serialized it, you can parse the string with a JSONParser:
ref: https://sites.google.com/site/gson/gson-user-guide#TOC-Array-Examples