List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.redhat.lightblue.crud.InsertionRequest.java
/** * Parses an insertion request from a json object. Unrecognized elements are * ignored./*ww w. ja v a2s . c o m*/ */ public static InsertionRequest fromJson(ObjectNode node) { InsertionRequest req = new InsertionRequest(); req.parse(node); JsonNode x = node.get("projection"); if (x != null) { req.returnFields = Projection.fromJson(x); } return req; }
From source file:com.redhat.lightblue.query.NaryValueRelationalExpression.java
/** * Parses an n-ary relational expression from the given json object *//*from w ww .j av a 2s .c o m*/ public static NaryValueRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { NaryRelationalOperator op = NaryRelationalOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("values"); if (x instanceof ArrayNode) { ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size()); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { values.add(Value.fromJson(itr.next())); } return new NaryValueRelationalExpression(field, op, values); } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); }
From source file:com.attribyte.essem.StatsParser.java
/** * Parses a stats response./*from w w w . j a v a2 s . c o m*/ * @param esObject The ES response object. * @return The parsed stats. */ public static Stats parseStats(ObjectNode esObject, RateUnit rateUnit) { //This assumes the "extended stats" aggregation. JsonNode aggregations = esObject.get("aggregations"); if (aggregations != null) { JsonNode stats = aggregations.get("stats"); if (stats != null) { Stats newStats = new Stats(getIntField(stats, "count", 0), getDoubleField(stats, "min", 0.0), getDoubleField(stats, "max", 0.0), getDoubleField(stats, "avg", 0.0), getDoubleField(stats, "sum", 0.0), getDoubleField(stats, "sum_of_squares", 0.0), getDoubleField(stats, "variance", 0.0), getDoubleField(stats, "std_deviation", 0.0)); return rateUnit != null ? newStats.scale(rateUnit.mult) : newStats; } else { return Stats.EMPTY_STATS; } } else { return Stats.EMPTY_STATS; } }
From source file:com.redhat.lightblue.query.UnsetExpression.java
/** * Parses an unset expression using the given json object *//*from ww w . j a v a 2 s. c o m*/ public static UnsetExpression fromJson(ObjectNode node) { if (node.size() == 1) { JsonNode val = node.get(UpdateOperator._unset.toString()); if (val != null) { List<Path> fields = new ArrayList<>(); if (val instanceof ArrayNode) { for (Iterator<JsonNode> itr = ((ArrayNode) val).elements(); itr.hasNext();) { fields.add(new Path(itr.next().asText())); } } else if (val.isValueNode()) { fields.add(new Path(val.asText())); } return new UnsetExpression(fields); } } throw Error.get(QueryConstants.ERR_INVALID_UNSET_EXPRESSION, node.toString()); }
From source file:com.attribyte.essem.StoredGraphParser.java
/** * Parses a stored graph response.// ww w . j av a 2s . co m * @param esObject The ES response object. * @return The list of graphs. */ public static List<StoredGraph> parseGraphs(ObjectNode esObject) throws IOException { List<StoredGraph> graphList = Lists.newArrayListWithExpectedSize(16); JsonNode hitsObj = esObject.get("hits"); if (hitsObj != null) { JsonNode hitsArr = hitsObj.get("hits"); if (hitsArr != null) { for (JsonNode hitObj : hitsArr) { JsonNode fieldsObj = hitObj.get("fields"); if (fieldsObj != null) { graphList.add(StoredGraph.fromJSON(fieldsObj)); } } } } return graphList; }
From source file:com.redhat.lightblue.crud.SaveRequest.java
/** * Parses a save request from a JSON object *//*from w ww.j av a 2 s . co m*/ public static SaveRequest fromJson(ObjectNode node) { SaveRequest req = new SaveRequest(); req.parse(node); JsonNode x = node.get("projection"); if (x != null) { req.returnFields = Projection.fromJson(x); } x = node.get("upsert"); if (x != null) { req.upsert = x.asBoolean(); } return req; }
From source file:org.onosproject.codec.impl.IntentCodec.java
/** * Extracts base intent specific attributes from a JSON object * and adds them to a builder./*from w w w .j a v a 2 s . co m*/ * * @param json root JSON object * @param context code context * @param builder builder to use for storing the attributes */ public static void intentAttributes(ObjectNode json, CodecContext context, Intent.Builder builder) { String appId = nullIsIllegal(json.get(IntentCodec.APP_ID), IntentCodec.APP_ID + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); CoreService service = context.getService(CoreService.class); builder.appId(service.getAppId(appId)); JsonNode priorityJson = json.get(IntentCodec.PRIORITY); if (priorityJson != null) { builder.priority(priorityJson.asInt()); } }
From source file:com.almende.salig.Client.java
private static Message createMessage(ObjectNode input) { final Message message = new Message(); message.setDateTime(DateTime.now().getMillis()); message.setValue(input.get("value").asBoolean()); message.setLicense("app1@kinect/" + input.get("type").asText() + "/string"); message.setSerial(input.get("type").asText() + "Detector"); return message; }
From source file:com.redhat.lightblue.DataError.java
/** * Parses a Json object node and returns the DataError corresponding to it. * It is up to the client to make sure that the object node is a DataError * representation. Any unrecognized elements are ignored. *///from w w w . j a va2 s.co m public static DataError fromJson(ObjectNode node) { DataError error = new DataError(); JsonNode x = node.get("data"); if (x != null) { error.entityData = x; } x = node.get("errors"); if (x instanceof ArrayNode) { error.errors = new ArrayList<>(); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { error.errors.add(Error.fromJson(itr.next())); } } return error; }
From source file:com.redhat.lightblue.crud.UpdateRequest.java
/** * Parses an update request from a Json object */// www.java2 s . c o m public static UpdateRequest fromJson(ObjectNode node) { UpdateRequest req = new UpdateRequest(); req.parse(node); JsonNode x = node.get("query"); if (x != null) { req.query = QueryExpression.fromJson(x); } x = node.get("update"); if (x != null) { req.updateExpression = UpdateExpression.fromJson(x); } x = node.get("projection"); if (x != null) { req.returnFields = Projection.fromJson(x); } return req; }