net.minidev.json.parser.ParseException Java Examples
The following examples show how to use
net.minidev.json.parser.ParseException.
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: Replay.java From scheduler with GNU Lesser General Public License v3.0 | 6 votes |
@Override public TestCase get() { try { String json = in.readLine(); if (json == null) { return null; } TestCase tc = TestCase.fromJSON(constraints, json); if (restriction.size() == 1) { if (restriction.contains(Restriction.CONTINUOUS) && !tc.impl().setContinuous(true)) { throw new IllegalArgumentException("Cannot be CONTINUOUS"); } else if (!tc.impl().setContinuous(false)) { throw new IllegalArgumentException("Cannot be DISCRETE"); } } return tc; } catch (IOException | ParseException | JSONConverterException e) { throw new IllegalArgumentException(e); } }
Example #2
Source File: JsonArrayLength.java From tajo with Apache License 2.0 | 6 votes |
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0)) { return NullDatum.get(); } try { Object parsed = parser.parse(params.getBytes(0)); if (parsed instanceof JSONArray) { JSONArray array = (JSONArray) parsed; return DatumFactory.createInt8(array.size()); } else { return NullDatum.get(); } } catch (ParseException e) { return NullDatum.get(); } }
Example #3
Source File: PyLint.java From warnings-ng-plugin with MIT License | 6 votes |
int initialize() { JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE); try { JSONArray elements = (JSONArray) parser.parse(PyLint.class.getResourceAsStream("pylint-descriptions.json")); for (Object element : elements) { JSONObject object = (JSONObject) element; String description = object.getAsString("description"); descriptionByName.put(object.getAsString("name"), description); descriptionById.put(object.getAsString("code"), description); } } catch (ParseException | UnsupportedEncodingException ignored) { // ignore all exceptions } return descriptionByName.size(); }
Example #4
Source File: XsuaaServicesParser.java From cloud-security-xsuaa-integration with Apache License 2.0 | 6 votes |
@Nullable private static JSONObject parseCredentials(String vcapServices) throws IOException { if (vcapServices == null || vcapServices.isEmpty()) { logger.warn("VCAP_SERVICES could not be load."); return null; } try { JSONObject vcapServicesJSON = (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(vcapServices); JSONObject xsuaaBinding = searchXsuaaBinding(vcapServicesJSON); if (Objects.nonNull(xsuaaBinding) && xsuaaBinding.containsKey(CREDENTIALS)) { return (JSONObject) xsuaaBinding.get(CREDENTIALS); } } catch (ParseException ex) { throw new IOException("Error while parsing XSUAA credentials from VCAP_SERVICES: {}.", ex); } return null; }
Example #5
Source File: Verify.java From dew with Apache License 2.0 | 6 votes |
/** * Verify resource descriptors. * * @param message the message * @param expectedText the expected text * @param actualText the actual text * @throws IOException the io exception * @throws ParseException the parse exception */ default void verifyResourceDescriptors(String message, String expectedText, String actualText) throws IOException, ParseException { JsonTextMessageValidator validator = new JsonTextMessageValidator(); validator.setStrict(false); TestContext context = new TestContext(); context.getValidationMatcherRegistry() .getValidationMatcherLibraries() .add(new ValidationMatcherConfig().getValidationMatcherLibrary()); validator.validateJson(message, (JSONObject) new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE).parse(toJson(actualText)), (JSONObject) new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE).parse(toJson(expectedText)), new JsonMessageValidationContext(), context, JsonPath.parse(actualText)); }
Example #6
Source File: PicaReaderTest.java From metadata-qa-marc with GNU General Public License v3.0 | 6 votes |
@NotNull private Map<String, List<PicaTagDefinition>> readSchema(JSONParser parser, String fileName) throws IOException, URISyntaxException, ParseException { Map<String, List<PicaTagDefinition>> map = new HashMap<>(); Path tagsFile = FileUtils.getPath(fileName); Object obj = parser.parse(new FileReader(tagsFile.toString())); JSONObject jsonObject = (JSONObject) obj; JSONObject fields = (JSONObject) jsonObject.get("fields"); for (String name : fields.keySet()) { JSONObject field = (JSONObject) fields.get(name); // System.err.println(field); PicaTagDefinition tag = new PicaTagDefinition( (String) field.get("pica3"), name, (boolean) field.get("repeatable"), false, (String) field.get("label") ); addTag(map, tag); } return map; }
Example #7
Source File: KafkaStubMessages.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
Message toMessage() { Object textPayload = record.value(); // sometimes it's a message sometimes just payload MessageHeaders headers = new MessageHeaders(toMap(record.headers())); if (textPayload instanceof String && ((String) textPayload).contains("payload") && ((String) textPayload).contains("headers")) { try { Object object = new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE) .parse((String) textPayload); JSONObject jo = (JSONObject) object; String payload = (String) jo.get("payload"); JSONObject headersInJson = (JSONObject) jo.get("headers"); Map newHeaders = new HashMap(headers); newHeaders.putAll(headersInJson); return MessageBuilder.createMessage(unquoted(payload), new MessageHeaders(newHeaders)); } catch (ParseException ex) { throw new IllegalStateException(ex); } } return MessageBuilder.createMessage(unquoted(textPayload), headers); }
Example #8
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 #9
Source File: MongoResultsWriter.java From spring-data-dev-tools with Apache License 2.0 | 5 votes |
private void doWrite(Collection<RunResult> results) throws ParseException { Date now = new Date(); StandardEnvironment env = new StandardEnvironment(); String projectVersion = env.getProperty("project.version", "unknown"); String gitBranch = env.getProperty("git.branch", "unknown"); String gitDirty = env.getProperty("git.dirty", "no"); String gitCommitId = env.getProperty("git.commit.id", "unknown"); ConnectionString uri = new ConnectionString(this.uri); MongoClient client = MongoClients.create(); String dbName = StringUtils.hasText(uri.getDatabase()) ? uri.getDatabase() : "spring-data-mongodb-benchmarks"; MongoDatabase db = client.getDatabase(dbName); String resultsJson = ResultsWriter.jsonifyResults(results).trim(); JSONArray array = (JSONArray) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(resultsJson); for (Object object : array) { JSONObject dbo = (JSONObject) object; String collectionName = extractClass(dbo.get("benchmark").toString()); Document sink = new Document(); sink.append("_version", projectVersion); sink.append("_branch", gitBranch); sink.append("_commit", gitCommitId); sink.append("_dirty", gitDirty); sink.append("_method", extractBenchmarkName(dbo.get("benchmark").toString())); sink.append("_date", now); sink.append("_snapshot", projectVersion.toLowerCase().contains("snapshot")); sink.putAll(dbo); db.getCollection(collectionName).insertOne(fixDocumentKeys(sink)); } client.close(); }
Example #10
Source File: UpdaterMapper.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * called when json-smart parser meet an object key */ public JsonReaderI<?> startObject(String key) throws ParseException, IOException { Object bean = mapper.getValue(obj, key); if (bean == null) return mapper.startObject(key); return new UpdaterMapper<Object>(base, bean, mapper.getType(key)); }
Example #11
Source File: JSONValue.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * Check Json Syntax from input String * * @return if the input is valid */ public static boolean isValidJson(String s) { try { new JSONParser(DEFAULT_PERMISSIVE_MODE).parse(s, FakeMapper.DEFAULT); return true; } catch (ParseException e) { return false; } }
Example #12
Source File: JSONValue.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * Check Json Syntax from input Reader * * @return if the input is valid */ public static boolean isValidJson(Reader in) throws IOException { try { new JSONParser(DEFAULT_PERMISSIVE_MODE).parse(in, FakeMapper.DEFAULT); return true; } catch (ParseException e) { return false; } }
Example #13
Source File: JSONValue.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * check RFC4627 Json Syntax from input String * * @return if the input is valid */ public static boolean isValidJsonStrict(String s) { try { new JSONParser(MODE_RFC4627).parse(s, FakeMapper.DEFAULT); return true; } catch (ParseException e) { return false; } }
Example #14
Source File: JSONValue.java From json-smart-v2 with Apache License 2.0 | 5 votes |
/** * Check RFC4627 Json Syntax from input Reader * * @return if the input is valid */ public static boolean isValidJsonStrict(Reader in) throws IOException { try { new JSONParser(MODE_RFC4627).parse(in, FakeMapper.DEFAULT); return true; } catch (ParseException e) { return false; } }
Example #15
Source File: MongoResultsWriter.java From spring-data-dev-tools with Apache License 2.0 | 5 votes |
@Override public void write(OutputFormat output, Collection<RunResult> results) { if (CollectionUtils.isEmpty(results)) { return; } try { doWrite(results); } catch (ParseException | RuntimeException e) { output.println("Failed to write results: " + e.toString()); } }
Example #16
Source File: JsonUtils.java From karate with MIT License | 5 votes |
public static DocumentContext toJsonDocStrict(String raw) { try { JSONParser parser = new JSONParser(JSONParser.MODE_RFC4627); Object o = parser.parse(raw.trim()); return JsonPath.parse(o); } catch (ParseException e) { throw new RuntimeException(e); } }
Example #17
Source File: JsonUtilsTest.java From karate with MIT License | 5 votes |
@Test public void testMalformed() { String text = FileUtils.toString(getClass().getResourceAsStream("malformed.txt")); try { Object o = JsonUtils.toJsonDocStrict(text); fail("we should not have reached here"); } catch (Exception e) { assertTrue(e.getCause() instanceof ParseException); } }
Example #18
Source File: TablespaceManager.java From tajo with Apache License 2.0 | 5 votes |
private static JSONObject parseJson(String json) { try { return (JSONObject) parser.parse(json); } catch (ParseException e) { throw new RuntimeException(e); } }
Example #19
Source File: Verify.java From jkube with Eclipse Public License 2.0 | 5 votes |
public static void verifyResourceDescriptors(File actualPath, File expectedPath, boolean strict) throws IOException, ParseException { String actualText = readFile(actualPath); String expectedText = readFile(expectedPath); JsonTextMessageValidator validator = new JsonTextMessageValidator(); validator.setStrict(strict); DocumentContext actualContext = JsonPath.parse(actualText); validator.validateJson(newMessage(actualText), newMessage(expectedText), new JsonMessageValidationContext(), createTestContext(), actualContext); }
Example #20
Source File: TestZeroLead.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void test0Float() throws Exception { String s = "[00.0]"; // strict MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0); // PERMISIVE JSONValue.parseWithException(s); }
Example #21
Source File: TestZeroLead.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void test01Float() throws Exception { String s = "[01.0]"; // strict MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0); // PERMISIVE JSONValue.parseWithException(s); }
Example #22
Source File: TestSpecialChar.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testSpecial127() throws Exception { String s127 = String.format("%c", 127); String s = String.format("[\"%c\"]", 127); MustThrows.testInvalidJson(s, JSONParser.MODE_STRICTEST, ParseException.ERROR_UNEXPECTED_CHAR); JSONArray o = (JSONArray) new JSONParser(JSONParser.MODE_RFC4627).parse(s); assertEquals(o.get(0), s127); }
Example #23
Source File: TestTaillingJunk.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testTaillingSpace() throws Exception { String s = "{\"t\":0} "; MustThrows.testInvalidJson(s, JSONParser.MODE_STRICTEST, ParseException.ERROR_UNEXPECTED_TOKEN); s = "{\"t\":0} "; JSONObject o = (JSONObject) new JSONParser(JSONParser.MODE_STRICTEST | JSONParser.ACCEPT_TAILLING_SPACE).parse(s); assertEquals(o.get("t"), 0); }
Example #24
Source File: MustThrows.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public static void testInvalidJson(String json, int permissifMode, int execptionType, Class<?> cls) throws Exception { JSONParser p = new JSONParser(permissifMode); try { if (cls == null) p.parse(json); else p.parse(json, cls); TestCase.assertFalse("Exception Should Occure parsing:" + json, true); } catch (ParseException e) { if (execptionType == -1) execptionType = e.getErrorType(); TestCase.assertEquals(execptionType, e.getErrorType()); } }
Example #25
Source File: PathsRetainerTest.java From json-smart-v2 with Apache License 2.0 | 5 votes |
@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 #26
Source File: PathLocatorTest.java From json-smart-v2 with Apache License 2.0 | 5 votes |
@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 #27
Source File: KeysPrintActionTest.java From json-smart-v2 with Apache License 2.0 | 5 votes |
@Test public void test() throws ParseException { KeysPrintAction p = new KeysPrintAction(); JSONTraverser t = new JSONTraverser(p); String data ="{" + "'k0':{" + "'k01':{" + "'k011':'v2'" + "}" + "}," + "'k1':{" + "'k11':{" + "'k111':'v5'" + "}," + "'k12':{" + "'k121':'v5'" + "}" + "}," + "'k3':{" + "'k31':{" + "'k311':'v5'" + "}" + "}" + "}"; JSONObject jo = (JSONObject) JSONValue.parseWithException(data.replace("'", "\"")); t.traverse(jo); }
Example #28
Source File: PathRemoverTest.java From json-smart-v2 with Apache License 2.0 | 5 votes |
@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 #29
Source File: ElementRemoverTest.java From json-smart-v2 with Apache License 2.0 | 5 votes |
@Test public void test() throws ParseException { JSONObject objectToClean = jsonToClean != null ? (JSONObject) JSONValue.parseWithException(jsonToClean) : null; JSONObject expectedObject = expectedJson != null ? (JSONObject) JSONValue.parseWithException(expectedJson) : null; JSONObject toRemove = elementsToRemove != null ? (JSONObject) JSONValue.parseWithException(elementsToRemove) : null; ElementRemover er = new ElementRemover(toRemove); er.remove(objectToClean); assertEquals(expectedObject, objectToClean); }
Example #30
Source File: JSONObjectConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
/** * Un-serialize an object from a stream. * The stream must be close afterward * * @param r the stream to read * @return the resulting object * @throws JSONConverterException if the stream cannot be parsed */ default E fromJSON(Reader r) throws JSONConverterException { try { JSONParser p = new JSONParser(JSONParser.MODE_RFC4627); Object o = p.parse(r); if (!(o instanceof JSONObject)) { throw new JSONConverterException("Unable to parse a JSON object"); } return fromJSON((JSONObject) o); } catch (ParseException ex) { throw new JSONConverterException(ex); } }