コード例 #1
0
 @Test
 public void testNullFiltering() {
   MapJsonRenderer renderer = new MapJsonRenderer(false);
   JSONStringer jsonWriter = new JSONStringer();
   jsonWriter.addRenderer(renderer);
   Map<String, Object> map = new LinkedHashMap<String, Object>();
   map.put(null, "gg");
   map.put("ff", null);
   jsonWriter.value(map);
   assertEquals(jsonWriter.toString(), "{}");
 }
コード例 #2
0
  /** allow null values but not null keys */
  @Test
  public void testAllowNulls() {
    MapJsonRenderer renderer = new MapJsonRenderer(true);
    JSONStringer jsonWriter = new JSONStringer();
    jsonWriter.addRenderer(renderer);
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("ff", null);
    jsonWriter.value(map);

    assertEquals(jsonWriter.toString(), "{\"ff\":null}");
  }
コード例 #3
0
  @SuppressWarnings("unchecked")
  @Test
  public void testBasic() {
    MapJsonRenderer renderer = new MapJsonRenderer(false);
    JSONStringer jsonWriter = new JSONStringer();
    jsonWriter.addRenderer(renderer);
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    jsonWriter.value(map);
    assertEquals(jsonWriter.toString(), "{}");

    jsonWriter = new JSONStringer();
    jsonWriter.addRenderer(renderer);
    map.put("foo", true);
    // check recursion
    map.put("bar", new LinkedHashMap());
    map.put("str", "\'\":);");
    jsonWriter.value(map);
    assertEquals(jsonWriter.toString(), "{\"foo\":true,\"bar\":{},\"str\":\"'\\\":);\"}");
  }