@Override public final Shape read(Reader reader) throws IOException, ParseException { return readShape(new JSONParser(reader)); }
public JSONTupleStream(Reader reader) { this.reader = reader; this.parser = new JSONParser(reader); }
public JSONTupleStream(Reader reader) { this.reader = reader; this.parser = new JSONParser(reader); }
/** * Creates an JSONParser on top of whatever reader has been * configured. Then calls getInst() with a handler which is * invoked forEach record emitted. * * @param r the stream reader * @param handler The callback instance */ public void streamRecords(Reader r, Handler handler) throws IOException { streamRecords(new JSONParser(r), handler); }
@Override public final Shape read(Reader reader) throws IOException, ParseException { return readShape(new JSONParser(reader)); }
public static Object fromJSON(String json) throws IOException { JSONParser p = new JSONParser(json); return getVal(p); }
@Override public final Shape read(Reader reader) throws IOException, ParseException { return readShape(new JSONParser(reader)); }
/** * Creates an JSONParser on top of whatever reader has been * configured. Then calls getInst() with a handler which is * invoked forEach record emitted. * * @param r the stream reader * @param handler The callback instance */ public void streamRecords(Reader r, Handler handler) throws IOException { streamRecords(new JSONParser(r), handler); }
public static Object fromJSON(String json) throws IOException { JSONParser p = new JSONParser(json); return getVal(p); }
public static Object fromJSONString(String json) { try { return new ObjectBuilder(new JSONParser(new StringReader( json))).getObject(); } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Parse error", e); } }
/** * @param input Object structure to parse and test against * @param pathAndExpected JSON path expression + '==' + expected value * @param delta tollerance allowed in comparing float/double values */ public static String matchObj(Object input, String pathAndExpected, double delta) throws Exception { int pos = pathAndExpected.indexOf("=="); String path = pos>=0 ? pathAndExpected.substring(0,pos) : null; String expected = pos>=0 ? pathAndExpected.substring(pos+2) : pathAndExpected; Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected); return matchObj(path, input, expectObj, delta); }
/** * @param path JSON path expression * @param input JSON Structure to parse and test against * @param expected expected value of path * @param delta tollerance allowed in comparing float/double values */ public static String match(String path, String input, String expected, double delta) throws Exception { Object inputObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(input)).getVal() : ObjectBuilder.fromJSON(input); Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected); return matchObj(path, inputObj, expectObj, delta); }
public static JSONParser getJSONParser(Reader reader){ JSONParser parser = new JSONParser(reader); parser.setFlags(parser.getFlags() | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT | JSONParser.OPTIONAL_OUTER_BRACES); return parser; }
@Override public NamedList<Object> processResponse(InputStream body, String encoding) { Map map = null; try { ObjectBuilder builder = new ObjectBuilder( new JSONParser(new InputStreamReader(body, encoding == null? "UTF-8": encoding))); map = (Map)builder.getObject(); } catch (IOException | JSONParser.ParseException e) { throw new SolrException (SolrException.ErrorCode.SERVER_ERROR, "parsing error", e); } NamedList<Object> list = new NamedList<Object>(); list.addAll(map); return list; }
public static ValidatingJsonMap fromJSON(Reader s, String includeLocation) { try { ValidatingJsonMap map = (ValidatingJsonMap) getObjectBuilder(new JSONParser(s)).getObject(); handleIncludes(map, includeLocation, 4); return map; } catch (IOException e) { throw new RuntimeException(); } }
public static Object fromJSON(byte[] utf8) { // convert directly from bytes to chars // and parse directly from that instead of going through // intermediate strings or readers CharArr chars = new CharArr(); ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars); JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length()); try { return ObjectBuilder.getVal(parser); } catch (IOException e) { throw new RuntimeException(e); // should never happen w/o using real IO } }
JSONParser parser = new JSONParser(rdr); parser.setFlags(parser.getFlags() | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT |
public static Object fromJSON(byte[] utf8) { // convert directly from bytes to chars // and parse directly from that instead of going through // intermediate strings or readers CharArr chars = new CharArr(); ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars); JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length()); try { return ObjectBuilder.getVal(parser); } catch (IOException e) { throw new RuntimeException(e); // should never happen w/o using real // IO } }
public static Object fromJSON(byte[] utf8) { // convert directly from bytes to chars // and parse directly from that instead of going through // intermediate strings or readers CharArr chars = new CharArr(); ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars); JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length()); parser.setFlags(parser.getFlags() | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT | JSONParser.OPTIONAL_OUTER_BRACES); try { return STANDARDOBJBUILDER.apply(parser).getVal(parser); } catch (IOException e) { throw new RuntimeException(e); // should never happen w/o using real IO } }