@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testParameterMapToJsonParsing() throws Exception { assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "1")), new JSONObject("{a:{b:{c:1}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "\"1\"")), new JSONObject("{a:{b:{c:\"1\"}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "true")), new JSONObject("{a:{b:{c:true}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "false")), new JSONObject("{a:{b:{c:false}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "null")), new JSONObject("{a:{b:{c:null}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b(0).c", "hello", "a.b(1).c", "hello")), new JSONObject("{a:{b:[{c:\"hello\"},{c:\"hello\"}]}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "hello, true, false, null, 1,2, \"null\", \"()\"")), new JSONObject("{a:{b:{c:[\"hello\",true,false,null,1,2,\"null\",\"()\"]}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "\"hello, true, false, null, 1,2\"")), new JSONObject("{a:{b:{c:\"hello, true, false, null, 1,2\"}}}")); }
@Test public void testParameterMapToJsonParsing() throws Exception { assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "1")), new JSONObject("{a:{b:{c:1}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "\"1\"")), new JSONObject("{a:{b:{c:\"1\"}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "true")), new JSONObject("{a:{b:{c:true}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "false")), new JSONObject("{a:{b:{c:false}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "null")), new JSONObject("{a:{b:{c:null}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b(0).c", "hello", "a.b(1).c", "hello")), new JSONObject("{a:{b:[{c:\"hello\"},{c:\"hello\"}]}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "hello, true, false, null, 1,2, \"null\", \"()\"")), new JSONObject("{a:{b:{c:[\"hello\",true,false,null,1,2,\"null\",\"()\"]}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "\"hello, true, false, null, 1,2\"")), new JSONObject("{a:{b:{c:\"hello, true, false, null, 1,2\"}}}")); }
@Test public void testParameterMapToJsonParsing() throws Exception { assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "1")), new JSONObject("{a:{b:{c:1}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "\"1\"")), new JSONObject("{a:{b:{c:\"1\"}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "true")), new JSONObject("{a:{b:{c:true}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "false")), new JSONObject("{a:{b:{c:false}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "null")), new JSONObject("{a:{b:{c:null}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b(0).c", "hello", "a.b(1).c", "hello")), new JSONObject("{a:{b:[{c:\"hello\"},{c:\"hello\"}]}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "hello, true, false, null, 1,2, \"null\", \"()\"")), new JSONObject("{a:{b:{c:[\"hello\",true,false,null,1,2,\"null\",\"()\"]}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "\"hello, true, false, null, 1,2\"")), new JSONObject("{a:{b:{c:\"hello, true, false, null, 1,2\"}}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testParameterMapToJsonParsing() throws Exception { assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "1")), new JSONObject("{a:{b:{c:1}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "\"1\"")), new JSONObject("{a:{b:{c:\"1\"}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "true")), new JSONObject("{a:{b:{c:true}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "false")), new JSONObject("{a:{b:{c:false}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "null")), new JSONObject("{a:{b:{c:null}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b(0).c", "hello", "a.b(1).c", "hello")), new JSONObject("{a:{b:[{c:\"hello\"},{c:\"hello\"}]}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "hello, true, false, null, 1,2, \"null\", \"()\"")), new JSONObject("{a:{b:{c:[\"hello\",true,false,null,1,2,\"null\",\"()\"]}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "\"hello, true, false, null, 1,2\"")), new JSONObject("{a:{b:{c:\"hello, true, false, null, 1,2\"}}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testValueToJsonParsing() throws Exception { String longNumber = "108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longNumber), longNumber); String longDoubleOverflow = "108502345354398668456.1234"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleOverflow), longDoubleOverflow); String longDoubleFractionPart = "1.108502345354398668456108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleFractionPart), longDoubleFractionPart); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12345"), 12345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12.345"), 12.345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("abc"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("\"a,b,c\""), "a,b,c"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("true"), true); assertJsonEquals(JsonConversionUtil.convertToJsonValue("false"), false); assertJsonEquals(JsonConversionUtil.convertToJsonValue("null"), JSONObject.NULL); assertJsonEquals(JsonConversionUtil.convertToJsonValue("'abc'"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("a,b,c"), new JSONArray(Lists.newArrayList("a", "b", "c"))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("1,2,3,true,false,null"), new JSONArray(Lists.<Object>newArrayList(1, 2, 3, true, false, null))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(1)"), new JSONArray(Lists.newArrayList(1))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(true)"), new JSONArray(Lists.newArrayList(true))); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testValueToJsonParsing() throws Exception { String longNumber = "108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longNumber), longNumber); String longDoubleOverflow = "108502345354398668456.1234"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleOverflow), longDoubleOverflow); String longDoubleFractionPart = "1.108502345354398668456108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleFractionPart), longDoubleFractionPart); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12345"), 12345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12.345"), 12.345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("abc"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("\"a,b,c\""), "a,b,c"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("true"), true); assertJsonEquals(JsonConversionUtil.convertToJsonValue("false"), false); assertJsonEquals(JsonConversionUtil.convertToJsonValue("null"), JSONObject.NULL); assertJsonEquals(JsonConversionUtil.convertToJsonValue("'abc'"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("a,b,c"), new JSONArray(Lists.newArrayList("a", "b", "c"))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("1,2,3,true,false,null"), new JSONArray(Lists.<Object>newArrayList(1, 2, 3, true, false, null))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(1)"), new JSONArray(Lists.newArrayList(1))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(true)"), new JSONArray(Lists.newArrayList(true))); }
@Test public void testParameterMapToJsonParsing() throws Exception { assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "1")), new JSONObject("{a:{b:{c:1}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "\"1\"")), new JSONObject("{a:{b:{c:\"1\"}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "true")), new JSONObject("{a:{b:{c:true}}}")); assertJsonEquals( JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "false")), new JSONObject("{a:{b:{c:false}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "null")), new JSONObject("{a:{b:{c:null}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b(0).c", "hello", "a.b(1).c", "hello")), new JSONObject("{a:{b:[{c:\"hello\"},{c:\"hello\"}]}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "hello, true, false, null, 1,2, \"null\", \"()\"")), new JSONObject("{a:{b:{c:[\"hello\",true,false,null,1,2,\"null\",\"()\"]}}}")); assertJsonEquals(JsonConversionUtil.parametersToJsonObject( ImmutableMap.of("a.b.c", "\"hello, true, false, null, 1,2\"")), new JSONObject("{a:{b:{c:\"hello, true, false, null, 1,2\"}}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testValueToJsonParsing() throws Exception { String longNumber = "108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longNumber), longNumber); String longDoubleOverflow = "108502345354398668456.1234"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleOverflow), longDoubleOverflow); String longDoubleFractionPart = "1.108502345354398668456108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleFractionPart), longDoubleFractionPart); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12345"), 12345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12.345"), 12.345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("abc"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("\"a,b,c\""), "a,b,c"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("true"), true); assertJsonEquals(JsonConversionUtil.convertToJsonValue("false"), false); assertJsonEquals(JsonConversionUtil.convertToJsonValue("null"), JSONObject.NULL); assertJsonEquals(JsonConversionUtil.convertToJsonValue("'abc'"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("a,b,c"), new JSONArray(Lists.newArrayList("a", "b", "c"))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("1,2,3,true,false,null"), new JSONArray(Lists.<Object>newArrayList(1, 2, 3, true, false, null))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(1)"), new JSONArray(Lists.newArrayList(1))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(true)"), new JSONArray(Lists.newArrayList(true))); }
@Test public void testValueToJsonParsing() throws Exception { String longNumber = "108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longNumber), longNumber); String longDoubleOverflow = "108502345354398668456.1234"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleOverflow), longDoubleOverflow); String longDoubleFractionPart = "1.108502345354398668456108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleFractionPart), longDoubleFractionPart); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12345"), 12345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12.345"), 12.345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("abc"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("\"a,b,c\""), "a,b,c"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("true"), true); assertJsonEquals(JsonConversionUtil.convertToJsonValue("false"), false); assertJsonEquals(JsonConversionUtil.convertToJsonValue("null"), JSONObject.NULL); assertJsonEquals(JsonConversionUtil.convertToJsonValue("'abc'"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("a,b,c"), new JSONArray(Lists.newArrayList("a", "b", "c"))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("1,2,3,true,false,null"), new JSONArray(Lists.<Object>newArrayList(1, 2, 3, true, false, null))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(1)"), new JSONArray(Lists.newArrayList(1))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(true)"), new JSONArray(Lists.newArrayList(true))); }
@Test public void testValueToJsonParsing() throws Exception { String longNumber = "108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longNumber), longNumber); String longDoubleOverflow = "108502345354398668456.1234"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleOverflow), longDoubleOverflow); String longDoubleFractionPart = "1.108502345354398668456108502345354398668456"; assertJsonEquals(JsonConversionUtil.convertToJsonValue(longDoubleFractionPart), longDoubleFractionPart); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12345"), 12345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("12.345"), 12.345); assertJsonEquals(JsonConversionUtil.convertToJsonValue("abc"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("\"a,b,c\""), "a,b,c"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("true"), true); assertJsonEquals(JsonConversionUtil.convertToJsonValue("false"), false); assertJsonEquals(JsonConversionUtil.convertToJsonValue("null"), JSONObject.NULL); assertJsonEquals(JsonConversionUtil.convertToJsonValue("'abc'"), "abc"); assertJsonEquals(JsonConversionUtil.convertToJsonValue("a,b,c"), new JSONArray(Lists.newArrayList("a", "b", "c"))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("1,2,3,true,false,null"), new JSONArray(Lists.<Object>newArrayList(1, 2, 3, true, false, null))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(1)"), new JSONArray(Lists.newArrayList(1))); assertJsonEquals(JsonConversionUtil.convertToJsonValue("(true)"), new JSONArray(Lists.newArrayList(true))); }