Gson does not support serialization of anonymous types.
See Duplicate Related Sotirios Delimanolis. Note that the double-binding initializer you used creates an anonymous subclass that has some unpleasant side effects, such as creating new classes every time you use it, and breaking things like Gson.
It will work if you created such a constructor:
class Ideone
{
public class Person {
public String Name;
public String Address;
public Person(String Name, String Address) {
this.Name = Name;
this.Address = Address;
}
}
public static void main (String[] args) throws java.lang.Exception
{
Person person = new Person("John", "London");
Gson gson = new Gson();
String jsonPerson = gson.toJson(person);
}
}
, ; .
Google Java