/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }