I'm having a problem serializing an object using Gson.
@XmlRootElement
class Foo implements Serializable {
private int number;
private String str;
public Foo() {
number = 10;
str = "hello";
}
}
Gson will serialize this into a JSON
{"number":10,"str":"hello"}
.
However, I want it to be
{"Foo":{"number":10,"str":"hello"}}
,
so basically including the top level element. I tried to google a way to do this in Gson, but no luck. Anyone knows if there is a way to achieve this?
Thanks!