For above json you must have this classes below:
Example.java
package com.example;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
public class Example {
@Expose
private To to;
public To getTo() {
return to;
}
public void setTo(To to) {
this.to = to;
}
}
To.java
package com.example;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
public class To {
@Expose
private List<String> names = new ArrayList<String>();
@Expose
private List<String> callerIds = new ArrayList<String>();
@Expose
private List<String> captions = new ArrayList<String>();
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public List<String> getCallerIds() {
return callerIds;
}
public void setCallerIds(List<String> callerIds) {
this.callerIds = callerIds;
}
public List<String> getCaptions() {
return captions;
}
public void setCaptions(List<String> captions) {
this.captions = captions;
}
}
Then you convert this classes into json string as follows:
Gson gson = new Gson();
To myTo=new To();
myTo.setNames(...);
myTo.setCallerIds(...);
myTO.setCaptions(...);
Example exm=new Example();
exm.setTo(myTo);
System.out.println(gson.toJson(exm));
0
solved JsonArray convert to java code [duplicate]