public static Object getVal(JSONParser parser) throws IOException { return new ObjectBuilder(parser).getVal(); }
public Object getVal() throws IOException { int ev = parser.lastEvent(); switch(ev) { case JSONParser.STRING: return getString(); case JSONParser.LONG: return getLong(); case JSONParser.NUMBER: return getNumber(); case JSONParser.BIGNUMBER: return getBigNumber(); case JSONParser.BOOLEAN: return getBoolean(); case JSONParser.NULL: return getNull(); case JSONParser.OBJECT_START: return getObject(); case JSONParser.OBJECT_END: return null; // OR ERROR? case JSONParser.ARRAY_START: return getArray(); case JSONParser.ARRAY_END: return null; // OR ERROR? case JSONParser.EOF: return null; // OR ERROR? default: return null; // OR ERROR? } }
public Object getArray() throws IOException { Object arr = newArray(); for(;;) { int ev = parser.nextEvent(); if (ev==JSONParser.ARRAY_END) return endArray(arr); Object val = getVal(); addArrayVal(arr, val); } }
public static Object fromJSON(String json) throws IOException { JSONParser p = new JSONParser(json); return getVal(p); }
); ObjectBuilder ob = new ObjectBuilder(parser); int ev = parser.nextEvent(); if (ev == JSONParser.OBJECT_END) return operations; Object key = ob.getKey(); ev = parser.nextEvent(); Object val = ob.getVal(); if (val instanceof List && !singletonCommands.contains(key)) { List list = (List) val;
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); } }
public static Long deleteAndGetVersion(String id, SolrParams params) throws Exception { if (params==null || params.get("versions") == null) { ModifiableSolrParams mparams = new ModifiableSolrParams(params); mparams.set("versions","true"); params = mparams; } String response = updateJ(jsonDelId(id), params); Map rsp = (Map)ObjectBuilder.fromJSON(response); List lst = (List)rsp.get("deletes"); if (lst == null || lst.size() == 0) return null; return (Long) lst.get(1); }
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(String json) throws IOException { JSONParser p = new JSONParser(json); return getVal(p); }
public Object getArray() throws IOException { Object arr = newArray(); for(;;) { int ev = parser.nextEvent(); if (ev==JSONParser.ARRAY_END) return endArray(arr); Object val = getVal(); addArrayVal(arr, val); } }
@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; }
/** * @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); }
public Object getVal() throws IOException { int ev = parser.lastEvent(); switch(ev) { case JSONParser.STRING: return getString(); case JSONParser.LONG: return getLong(); case JSONParser.NUMBER: return getNumber(); case JSONParser.BIGNUMBER: return getBigNumber(); case JSONParser.BOOLEAN: return getBoolean(); case JSONParser.NULL: return getNull(); case JSONParser.OBJECT_START: return getObject(); case JSONParser.OBJECT_END: return null; // OR ERROR? case JSONParser.ARRAY_START: return getArray(); case JSONParser.ARRAY_END: return null; // OR ERROR? case JSONParser.EOF: return null; // OR ERROR? default: return null; // OR ERROR? } }
public static Object fromJSON(InputStream is){ try { return STANDARDOBJBUILDER.apply(getJSONParser((new InputStreamReader(is, StandardCharsets.UTF_8)))).getVal(); } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Parse error", e); } }
public static Object getVal(JSONParser parser) throws IOException { return new ObjectBuilder(parser).getVal(); }
public static Long addAndGetVersion(SolrInputDocument sdoc, SolrParams params) throws Exception { if (params==null || params.get("versions") == null) { ModifiableSolrParams mparams = new ModifiableSolrParams(params); mparams.set("versions","true"); params = mparams; } String response = updateJ(jsonAdd(sdoc), params); Map rsp = (Map)ObjectBuilder.fromJSON(response); List lst = (List)rsp.get("adds"); if (lst == null || lst.size() == 0) return null; return (Long) lst.get(1); }
public static Object fromJSON(InputStream is, Function<JSONParser, ObjectBuilder> objBuilderProvider) { try { return objBuilderProvider.apply(getJSONParser((new InputStreamReader(is, StandardCharsets.UTF_8)))).getVal(); } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Parse error", e); } }
public static Long deleteByQueryAndGetVersion(String q, SolrParams params) throws Exception { if (params==null || params.get("versions") == null) { ModifiableSolrParams mparams = new ModifiableSolrParams(params); mparams.set("versions","true"); params = mparams; } String response = updateJ(jsonDelQ(q), params); Map rsp = (Map)ObjectBuilder.fromJSON(response); List lst = (List)rsp.get("deleteByQuery"); if (lst == null || lst.size() == 0) return null; return (Long) lst.get(1); }