Code example for Gson

Methods: fromJson

0
    String json = gson.toJson(value);
    assertEquals("\"a\\\\b\"", json);
  } 
 
  public void testEscapedBackslashInStringDeserialization() throws Exception { 
    String actual = gson.fromJson("'a\\\\b'", String.class);
    assertEquals("a\\b", actual);
  } 
 
  public void testSingleQuoteInStringDeserialization() throws Exception { 
    String value = "beforeQuote'afterQuote";
    String actual = gson.fromJson("\"" + value + "\"", String.class);
    assertEquals(value, actual);
  } 
 
  public void testEscapingQuotesInStringSerialization() throws Exception { 
    String valueWithQuotes = "beforeQuote\"afterQuote";
    String jsonRepresentation = gson.toJson(valueWithQuotes);
    String target = gson.fromJson(jsonRepresentation, String.class);
    assertEquals(valueWithQuotes, target);
Contextual code suggestions in your IDE  Get Codota for Java