Code example for Gson

Methods: toJson

0
public class SimpleGsonTest { 
	 
    @Test 
    public void testGson(){ 
 
        Gson gson = new Gson();
 
        Person roger = new Person("Roger", "Federer", "roger@gmail.com");
 
        String json = gson.toJson(roger, Person.class);
 
        assertEquals("{\"firstName\":\"Roger\",\"lastName\":\"Federer\",\"email\":\"roger@gmail.com\"}", json);
 
        Person result = gson.fromJson(json, Person.class);
 
        assertEquals(result.getEmail(), roger.getEmail());
 
 
    }