Java Code Examples for net.minidev.json.JSONValue#toJSONString()
The following examples show how to use
net.minidev.json.JSONValue#toJSONString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestFieldRename.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testRemap() throws Exception { String text = "{'new':'foo','default':'bar'}"; JSONValue.remapField(TRen.class, "default", "default_"); JSONValue.remapField(TRen.class, "new", "new_"); TRen t = JSONValue.parse(text, TRen.class); assertEquals(t.new_, "foo"); assertEquals(t.default_, "bar"); String dest = JSONValue.toJSONString(t); assertTrue(dest.contains("\"default\"")); }
Example 2
Source File: TestCustomMappingInstant.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void test_dummy() throws IOException { @SuppressWarnings("unused") ParseException e = null; JSONValue.toJSONString(true, JSONStyle.MAX_COMPRESS); //Assert.assertEquals(true, true); }
Example 3
Source File: TestWriteFeatures.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testS1() throws Exception { Beans beans = new Beans(); String s = JSONValue.toJSONString(beans, JSONStyle.MAX_COMPRESS); assertEquals("{}", s); s = JSONValue.toJSONString(beans, JSONStyle.NO_COMPRESS); if (s.startsWith("{\"b")) { assertEquals("{\"b\":null,\"a\":null}", s); } else { assertEquals("{\"a\":null,\"b\":null}", s); } beans.a = "a"; s = JSONValue.toJSONString(beans, JSONStyle.MAX_COMPRESS); assertEquals("{a:a}", s); }
Example 4
Source File: TestBigValue.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * test BigDecimal serialization */ public void testBigDecimal() { HashMap<String, Object> map = new HashMap<String, Object>(); BigDecimal bigDec = new BigDecimal(bigStr + "." + bigStr); map.put("big", bigDec); String test = JSONValue.toJSONString(map); String result = "{\"big\":" + bigStr + "." +bigStr + "}"; assertEquals(result, test); JSONObject obj = (JSONObject)JSONValue.parse(test); assertEquals(bigDec, obj.get("big")); assertEquals(bigDec.getClass(), obj.get("big").getClass()); }
Example 5
Source File: TestBigValue.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * test BigInteger serialization */ public void testBigInteger() { HashMap<String, Object> map = new HashMap<String, Object>(); BigInteger bigInt = new BigInteger(bigStr); map.put("big", bigInt); String test = JSONValue.toJSONString(map); String result = "{\"big\":" + bigStr + "}"; assertEquals(result, test); JSONObject obj = (JSONObject)JSONValue.parse(test); assertEquals(bigInt, obj.get("big")); assertEquals(bigInt.getClass(), obj.get("big").getClass()); }
Example 6
Source File: TestInvalidNumber.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testF1() { String test = "51e88"; JSONObject o = new JSONObject(); o.put("a", test); String comp = JSONValue.toJSONString(o, JSONStyle.MAX_COMPRESS); assertEquals("{a:\"51e88\"}", comp); o = JSONValue.parse(comp, JSONObject.class); assertEquals(o.get("a"), test); }
Example 7
Source File: TestInvalidNumber.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testF2() { String test = "51e+88"; JSONObject o = new JSONObject(); o.put("a", test); String comp = JSONValue.toJSONString(o, JSONStyle.MAX_COMPRESS); assertEquals("{a:\"51e+88\"}", comp); o = JSONValue.parse(comp, JSONObject.class); assertEquals(o.get("a"), test); }
Example 8
Source File: TestInvalidNumber.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testF3() { String test = "51e-88"; JSONObject o = new JSONObject(); o.put("a", test); String comp = JSONValue.toJSONString(o, JSONStyle.MAX_COMPRESS); assertEquals("{a:\"51e-88\"}", comp); o = JSONValue.parse(comp, JSONObject.class); assertEquals(o.get("a"), test); }
Example 9
Source File: TestInvalidNumber.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testF4() { String test = "51ee88"; JSONObject o = new JSONObject(); o.put("a", test); String comp = JSONValue.toJSONString(o, JSONStyle.MAX_COMPRESS); assertEquals("{a:51ee88}", comp); o = JSONValue.parse(comp, JSONObject.class); assertEquals(o.get("a"), test); }
Example 10
Source File: JsonUtils.java From karate with MIT License | 4 votes |
public static String toJson(Object o) { return JSONValue.toJSONString(o); }
Example 11
Source File: MappingToJson.java From metadata-qa-marc with GNU General Public License v3.0 | 4 votes |
public String toJson() { return JSONValue.toJSONString(mapping); }
Example 12
Source File: TestDate.java From json-smart-v2 with Apache License 2.0 | 4 votes |
public void testBooleans() throws Exception { String s = "[true,true,false]"; boolean[] bs = new boolean[] { true, true, false }; String s2 = JSONValue.toJSONString(bs); assertEquals(s, s2); }
Example 13
Source File: TestDate.java From json-smart-v2 with Apache License 2.0 | 4 votes |
public void testInts() throws Exception { String s = "[1,2,3]"; int[] bs = new int[] { 1, 2, 3 }; String s2 = JSONValue.toJSONString(bs); assertEquals(s, s2); }
Example 14
Source File: TestMisc.java From json-smart-v2 with Apache License 2.0 | 4 votes |
public void testIssue23() throws Exception { String s = JSONValue.toJSONString(new int[] { 1, 2, 50, 1234, 10000 }); assertEquals("[1,2,50,1234,10000]", s); }