Search in sources :

Example 1 with Student

use of com.gpcoder.gson.object.Student in project Java-Tutorial by gpcodervn.

the class SerializedNameExample method main.

public static void main(String[] args) {
    final GsonBuilder builder = new GsonBuilder();
    final Gson gson = builder.create();
    final Student student = new Student(1, "GP Coder", "Java Dev");
    final String json = gson.toJson(student);
    System.out.println("Json: " + json);
    final Student student2 = gson.fromJson(json, Student.class);
    System.out.println("Java Object: " + student2);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Student(com.gpcoder.gson.object.Student)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Student (com.gpcoder.gson.object.Student)1