/** * Parses the given input string as JSON. The input must contain a valid JSON value, optionally * padded with whitespace. * * @param string * the input string, must be valid JSON * @return a value that represents the parsed JSON * @throws ParseException * if the input is not valid JSON */ public static JsonValue parse(String string) { if (string == null) { throw new NullPointerException("string is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(string); return handler.getValue(); }
/** * Reads the entire input from the given reader and parses it as JSON. The input must contain a * valid JSON value, optionally padded with whitespace. * <p> * Characters are read in chunks into an input buffer. Hence, wrapping a reader in an additional * <code>BufferedReader</code> likely won't improve reading performance. * </p> * * @param reader * the reader to read the JSON value from * @return a value that represents the parsed JSON * @throws IOException * if an I/O error occurs in the reader * @throws ParseException * if the input is not valid JSON */ public static JsonValue parse(Reader reader) throws IOException { if (reader == null) { throw new NullPointerException("reader is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(reader); return handler.getValue(); }
/** * Reads a JSON value from the given string. * * @param text * the string that contains the JSON value * @return the JSON value that has been read * @throws ParseException * if the input is not valid JSON */ public static JsonValue readFrom( String text ) { try { return new JsonParser( text ).parse(); } catch( IOException exception ) { // JsonParser does not throw IOException for String throw new RuntimeException( exception ); } }
/** * Reads a JSON value from the given reader. * <p> * Characters are read in chunks and buffered internally, therefore wrapping an existing reader in * an additional <code>BufferedReader</code> does <strong>not</strong> improve reading * performance. * </p> * * @param reader * the reader to read the JSON value from * @return the JSON value that has been read * @throws IOException * if an I/O error occurs in the reader * @throws ParseException * if the input is not valid JSON */ public static JsonValue readFrom( Reader reader ) throws IOException { return new JsonParser( reader ).parse(); }
private static <T> T parseJsonValue(final String jsonString, final DittoJsonHandler<?, ?, T> dittoJsonHandler) { requireNonNull(jsonString, "The JSON string to be parsed must not be null!"); new JsonParser(dittoJsonHandler).parse(jsonString); return dittoJsonHandler.getValue(); }
private static JsonValue readJsonValueFrom(final Reader reader) throws IOException { requireNonNull(reader, "The reader must not be null!"); final DefaultDittoJsonHandler dittoJsonHandler = DefaultDittoJsonHandler.newInstance(); new JsonParser(dittoJsonHandler).parse(reader); return dittoJsonHandler.getValue(); }
/** * Parses the given input string as JSON. The input must contain a valid JSON value, optionally * padded with whitespace. * * @param string * the input string, must be valid JSON * @return a value that represents the parsed JSON * @throws ParseException * if the input is not valid JSON */ public static JsonValue parse(String string) { if (string == null) { throw new NullPointerException("string is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(string); return handler.getValue(); }
/** * Parses the given input string as JSON. The input must contain a valid JSON value, optionally * padded with whitespace. * * @param string * the input string, must be valid JSON * @return a value that represents the parsed JSON * @throws ParseException * if the input is not valid JSON */ public static JsonValue parse(String string) { if (string == null) { throw new NullPointerException("string is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(string); return handler.getValue(); }
/** * Reads the entire input from the given reader and parses it as JSON. The input must contain a * valid JSON value, optionally padded with whitespace. * <p> * Characters are read in chunks into an input buffer. Hence, wrapping a reader in an additional * <code>BufferedReader</code> likely won't improve reading performance. * </p> * * @param reader * the reader to read the JSON value from * @return a value that represents the parsed JSON * @throws IOException * if an I/O error occurs in the reader * @throws ParseException * if the input is not valid JSON */ public static JsonValue parse(Reader reader) throws IOException { if (reader == null) { throw new NullPointerException("reader is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(reader); return handler.getValue(); }
/** * Reads the entire input from the given reader and parses it as JSON. The input must contain a * valid JSON value, optionally padded with whitespace. * <p> * Characters are read in chunks into an input buffer. Hence, wrapping a reader in an additional * <code>BufferedReader</code> likely won't improve reading performance. * </p> * * @param reader * the reader to read the JSON value from * @return a value that represents the parsed JSON * @throws IOException * if an I/O error occurs in the reader * @throws ParseException * if the input is not valid JSON */ public static JsonValue parse(Reader reader) throws IOException { if (reader == null) { throw new NullPointerException("reader is null"); } DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(reader); return handler.getValue(); }