Code example for JsonObject

Methods: addProperty

0
    String json = gson.toJson(list);
    assertContainsNoWhiteSpace(json);
  } 
 
  public void testJsonObjectWithNullValues() { 
    JsonObject obj = new JsonObject();
    obj.addProperty("field1", "value1");
    obj.addProperty("field2", (String) null);
    String json = gson.toJson(obj);
    assertTrue(json.contains("field1"));
    assertFalse(json.contains("field2"));
  } 
 
  public void testJsonObjectWithNullValuesSerialized() { 
    gson = new GsonBuilder().serializeNulls().create();
    JsonObject obj = new JsonObject();
    obj.addProperty("field1", "value1");
    obj.addProperty("field2", (String) null);
    String json = gson.toJson(obj);
    assertTrue(json.contains("field1"));
Contextual code suggestions in your IDE  Get Codota for Java