@Test public void encodesPrimitives() throws IOException { Map<String, Object> map = ImmutableMap.<String, Object>builder() .put("byte", (byte) 32) .put("boolean", true) .put("short", (short) 100) .put("int", 1) .put("long", 43L) .put("float", 23f) .put("double", Math.PI) .put("char", 'a') .put("String", "string") .build(); assertThat(cartographer.toJson(map)).isEqualTo("{\n" + " \"byte\": 32,\n" + " \"boolean\": true,\n" + " \"short\": 100,\n" + " \"int\": 1,\n" + " \"long\": 43,\n" + " \"float\": 23.0,\n" + " \"double\": 3.141592653589793,\n" + " \"char\": \"a\",\n" + " \"String\": \"string\"\n" + "}"); }
public String toJson(Map<?, ?> map) { StringWriter stringWriter = new StringWriter(); try { toJson(map, stringWriter); } catch (IOException e) { throw new AssertionError(e); } return stringWriter.toString(); }
Cartographer { public String toJson(Map<?, ?> map) { StringWriter stringWriter = new StringWriter(); try { toJson(map, stringWriter); } catch (IOException e) { throw new AssertionError(e); } return stringWriter.toString(); } }
Cartographer { public String toJson(Map<?, ?> map) { StringWriter stringWriter = new StringWriter(); try { toJson(map, stringWriter); } catch (IOException e) { throw new AssertionError(e); } return stringWriter.toString(); } Cartographer(boolean isLenient, boolean prettyPrint); }
Cartographer { public String toJson(Map<?, ?> map) { StringWriter stringWriter = new StringWriter(); try { toJson(map, stringWriter); } catch (IOException e) { throw new AssertionError(e); } return stringWriter.toString(); } Cartographer(boolean isLenient, boolean prettyPrint); Map<String, Object> fromJson(String json); Map<String, Object> fromJson(Reader reader); String toJson(Map<?, ?> map); void toJson(Map<?, ?> map, Writer writer); }
Cartographer { public String toJson(Map<?, ?> map) { StringWriter stringWriter = new StringWriter(); try { toJson(map, stringWriter); } catch (IOException e) { throw new AssertionError(e); } return stringWriter.toString(); } Cartographer(boolean isLenient, boolean prettyPrint); Map<String, Object> fromJson(String json); Map<String, Object> fromJson(Reader reader); String toJson(Map<?, ?> map); void toJson(Map<?, ?> map, Writer writer);  }