JSONSerializer { public static String serialize(Object object) { return serialize(object, false); } protected  JSONSerializer(String string); static String serialize(Object object); static String serialize(Object object, boolean addType); static Object deserialize(String json);  }
@Test public void testSerialize() { Assert.assertEquals(JSONSerializer.serialize(null), "null"); Assert.assertEquals(JSONSerializer.serialize((byte) 1), "1"); Assert.assertEquals(JSONSerializer.serialize((short) 1), "1"); Assert.assertEquals(JSONSerializer.serialize(-1), "-1"); Assert.assertEquals(JSONSerializer.serialize(1l), "1"); Assert.assertEquals(JSONSerializer.serialize(1.0d), "1.0"); Assert.assertEquals(JSONSerializer.serialize(1.0f), "1.0"); Assert.assertEquals(JSONSerializer.serialize(true), "true"); Assert.assertEquals(JSONSerializer.serialize(false), "false"); Assert.assertEquals(JSONSerializer.serialize('c'), "\"c\""); Assert.assertEquals(JSONSerializer.serialize("c"), "\"c\""); Assert.assertEquals(JSONSerializer.serialize("\"c\""), "\"\\\"c\\\"\""); Assert.assertEquals(JSONSerializer.serialize(new String[] {}), "[]"); Assert.assertEquals(JSONSerializer.serialize(new String[] { "1", "2" }), "[\"1\",\"2\"]"); List list = new ArrayList(); Assert.assertEquals(JSONSerializer.serialize(list), "[]"); list.add("1"); list.add("2"); Assert.assertEquals(JSONSerializer.serialize(list), "[\"1\",\"2\"]"); Map map = new HashMap(); Assert.assertEquals(JSONSerializer.serialize(map), "{}"); map.put("1", "2"); Assert.assertEquals(JSONSerializer.serialize(map), "{\"1\":\"2\"}"); }