Code example for Gson

Methods: toJson

0
    super.setUp(); 
    gson = new Gson();
  } 
 
  public void testPrimitiveCharacterAutoboxedSerialization() { 
    assertEquals("\"A\"", gson.toJson('A'));
    assertEquals("\"A\"", gson.toJson('A', char.class));
    assertEquals("\"A\"", gson.toJson('A', Character.class));
  } 
 
  public void testPrimitiveCharacterAutoboxedDeserialization() { 
    char expected = 'a';
    char actual = gson.fromJson("a", char.class);
    assertEquals(expected, actual);
 
    actual = gson.fromJson("\"a\"", char.class);
    assertEquals(expected, actual);
 
    actual = gson.fromJson("a", Character.class);
    assertEquals(expected, actual);
Experience pair programming with AI  Get Codota for Java