Looking for java Answers? Try Ask4KnowledgeBase
Looking for java Keywords? Try Ask4Keywords

Java Language JSON To Object (Gson Library)


Lets assume you have a class called Person with just name

private class Person {
    public String name;

    public Person(String name) {
        this.name = name;


Gson gson = new Gson();
String json = "{\"name\": \"John\"}";

Person person = gson.fromJson(json, Person.class);
System.out.println(person.name); //John

You must have gson library in your classpath.