Java Code Examples for net.minidev.json.JSONValue#parseWithException()

The following examples show how to use net.minidev.json.JSONValue#parseWithException() . 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: PathRemoverTest.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws ParseException
{
	JSONObject objectToClean = jsonToClean != null ? (JSONObject) JSONValue.parseWithException(jsonToClean) : null;
	JSONObject expectedObject = expectedJson != null ? (JSONObject) JSONValue.parseWithException(expectedJson): null;
	PathRemover cl = switchKeyToRemove();
	cl.remove(objectToClean);
	assertEquals(expectedObject, objectToClean);
}
 
Example 2
Source File: PathsRetainerTest.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws ParseException {
	JSONObject objectToReduce = jsonToReduce != null ? (JSONObject) JSONValue.parseWithException(jsonToReduce) : null;
	JSONObject expectedReducedObj = expectedReducedJson != null ? (JSONObject) JSONValue.parseWithException(expectedReducedJson) : null;
	PathsRetainer retainer = switchKeyToRemove().with(new DotDelimiter().withAcceptDelimiterInNodeName(false));
	JSONObject reducedObj = retainer.retain(objectToReduce);
	assertEquals(expectedReducedObj, reducedObj);
}
 
Example 3
Source File: PathReplicatorTest.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	JSONObject objectSource = jsonSource != null ? (JSONObject) JSONValue.parseWithException(jsonSource) : null;
	PathReplicator copier = switchKeyToCopy();
	JSONObject copied = copier.replicate(objectSource);
	JSONObject expectedObj = expected != null ? (JSONObject) JSONValue.parseWithException((String) expected) : null;
	assertEquals(expectedObj, copied);
}
 
Example 4
Source File: PathReplicatorTest.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test2() throws Exception {
	JSONObject objectSource = jsonSource != null ? (JSONObject) JSONValue.parseWithException(jsonSource) : null;
	PathReplicator copier = switchKeyToCopy2();
	JSONObject copied = copier.replicate(objectSource);
	JSONObject expectedObj = expected != null ? (JSONObject) JSONValue.parseWithException((String) expected) : null;
	assertEquals(expectedObj, copied);
}
 
Example 5
Source File: TestZeroLead.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public void test01Float() throws Exception {
	String s = "[01.0]";
	// strict
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0);
	// PERMISIVE
	JSONValue.parseWithException(s);
}
 
Example 6
Source File: TestZeroLead.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public void test0Float() throws Exception {
	String s = "[00.0]";
	// strict
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0);
	// PERMISIVE
	JSONValue.parseWithException(s);
}
 
Example 7
Source File: PathLocatorTest.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws ParseException
{
	JSONObject objectToSearch = jsonToSearch != null ? (JSONObject) JSONValue.parseWithException(jsonToSearch) : null;
	PathLocator locator = switchKeyToRemove();
	List<String> found = locator.locate(objectToSearch);
	assertEquals(Arrays.asList(expectedFound), found);
}
 
Example 8
Source File: TestMisc.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public void testBool() throws Exception {
	String s = "{\"key1\":\"v1\", \"key2\":{}, \"key3\":[]}";
	JSONObject o = (JSONObject) JSONValue.parseWithException(s);

	assertEquals(o.get("key1"), "v1");
	assertEquals(((JSONObject) o.get("key2")).size(), 0);
	assertEquals(((JSONArray) o.get("key3")).size(), 0);
}
 
Example 9
Source File: OpenIDConnectAuthenticator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected void buildClaimMappings(Map<ClaimMapping, String> claims, Map.Entry<String, Object> entry, String
        separator) {
    String claimValue = null;
    if (StringUtils.isBlank(separator)) {
        separator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT;
    }
    try {
        JSONArray jsonArray = (JSONArray) JSONValue.parseWithException(entry.getValue().toString());
        if (jsonArray != null && jsonArray.size() > 0) {
            Iterator attributeIterator = jsonArray.iterator();
            while (attributeIterator.hasNext()) {
                if (claimValue == null) {
                    claimValue = attributeIterator.next().toString();
                } else {
                    claimValue = claimValue + separator + attributeIterator.next().toString();
                }
            }

        }
    } catch (Exception e) {
        claimValue = entry.getValue().toString();
    }

    claims.put(ClaimMapping.build(entry.getKey(), entry.getKey(), null, false), claimValue);
    if (log.isDebugEnabled() && IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
        log.debug("Adding claim mapping : " + entry.getKey() + " <> " + entry.getKey() + " : " + claimValue);
    }

}
 
Example 10
Source File: TestMisc.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testFloat4() throws Exception {
	String s = "123é.5";
	Object o = JSONValue.parseWithException(s);
	assertEquals(o, 123);
}
 
Example 11
Source File: TestMisc.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testFloat3() throws Exception {
	String s = "123..5";
	Object o = JSONValue.parseWithException(s);
	assertEquals(o, "123..5");
}
 
Example 12
Source File: TestExcessiveComma.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testExcessiveComma3O() throws Exception {
	String s = "{,}";
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_CHAR);
	JSONValue.parseWithException(s);
}
 
Example 13
Source File: TestMisc.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testFloat2() throws Exception {
	String s = "123.5E1";
	Object o = JSONValue.parseWithException(s);
	assertEquals(o, new Double(1235));
}
 
Example 14
Source File: TestMisc.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testFloat() throws Exception {
	String s = "123.5";
	Object o = JSONValue.parseWithException(s);
	assertEquals(o, new Double(123.5));
}
 
Example 15
Source File: TestZeroLead.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void test00001() throws Exception {
	String s = "{\"t\":00001}";
	JSONObject o = (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(s);
	assertEquals(o.get("t"), 1);
	JSONValue.parseWithException(s);
}
 
Example 16
Source File: TestZeroLead.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void test00001Strict() throws Exception {
	String s = "{\"t\":00001}";
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0);
	JSONValue.parseWithException(s);
}
 
Example 17
Source File: TestMisc.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testInt() throws Exception {
	String s = "123";
	Object o = JSONValue.parseWithException(s);
	assertEquals(o, 123);
}
 
Example 18
Source File: TestExcessiveComma.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testExcessiveComma4A() throws Exception {
	String s = "[,5]";
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_CHAR);
	JSONValue.parseWithException(s);
}
 
Example 19
Source File: TestExcessiveComma.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testExcessiveComma1O() throws Exception {
	String s = "{\"a\":1,,\"b\":1}";
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_CHAR);
	JSONValue.parseWithException(s);
}
 
Example 20
Source File: TestExcessiveComma.java    From json-smart-v2 with Apache License 2.0 4 votes vote down vote up
public void testExcessiveComma2O() throws Exception {
	String s = "{\"a\":1,}";
	MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_CHAR);
	JSONValue.parseWithException(s);
}