Code example for Gson

0
  private Gson gson;
 
  @Override 
  protected void setUp() throws Exception { 
    super.setUp(); 
    gson = new Gson();
  } 
 
  @SuppressWarnings({"unchecked", "rawtypes"}) 
  public void testCompactFormattingLeavesNoWhiteSpace() { 
    List list = new ArrayList();
    list.add(new BagOfPrimitives());
    list.add(new Nested());
    list.add(new PrimitiveArray());
    list.add(new ClassWithTransientFields());
 
    String json = gson.toJson(list);
    assertContainsNoWhiteSpace(json);
  }