@Test public void testFromJson() throws IOException { List<FieldAndRValue> list = new ArrayList<>(); FieldAndRValue fav = new FieldAndRValue(); fav.setField(Path.EMPTY); fav.setRValue(new RValueExpression(Path.EMPTY)); list.add(fav); SetExpression expResult = new SetExpression(UpdateOperator._set, list); SetExpression result = SetExpression.fromJson((ObjectNode) JsonUtils.json("{\"$set\":{\"\":{\"$valueof\":\"\"}}}")); assertEquals(expResult, result); }
public static SetExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = null; if (node.has(UpdateOperator._add.toString())) { op = UpdateOperator._add; } else if (node.has(UpdateOperator._set.toString())) { op = UpdateOperator._set; } if (op != null) { ObjectNode arg = (ObjectNode) node.get(op.toString()); List<FieldAndRValue> list = new ArrayList<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = arg.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); Path field = new Path(entry.getKey()); RValueExpression rvalue = RValueExpression.fromJson(entry.getValue()); list.add(new FieldAndRValue(field, rvalue)); } return new SetExpression(op, list); } } throw Error.get(QueryConstants.ERR_INVALID_SET_EXPRESSION, node.toString()); }
SetExpression extends PrimitiveUpdateExpression { public static SetExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = null; if (node.has(UpdateOperator._add.toString())) { op = UpdateOperator._add; } else if (node.has(UpdateOperator._set.toString())) { op = UpdateOperator._set; } if (op != null) { ObjectNode arg = (ObjectNode) node.get(op.toString()); List<FieldAndRValue> list = new ArrayList<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = arg.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); Path field = new Path(entry.getKey()); RValueExpression rvalue = RValueExpression.fromJson(entry.getValue()); list.add(new FieldAndRValue(field, rvalue)); } return new SetExpression(op, list); } } throw Error.get(QueryConstants.ERR_INVALID_SET_EXPRESSION, node.toString()); } }
SetExpression extends PrimitiveUpdateExpression { public static SetExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = null; if (node.has(UpdateOperator._add.toString())) { op = UpdateOperator._add; } else if (node.has(UpdateOperator._set.toString())) { op = UpdateOperator._set; } if (op != null) { ObjectNode arg = (ObjectNode) node.get(op.toString()); List<FieldAndRValue> list = new ArrayList<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = arg.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); Path field = new Path(entry.getKey()); RValueExpression rvalue = RValueExpression.fromJson(entry.getValue()); list.add(new FieldAndRValue(field, rvalue)); } return new SetExpression(op, list); } } throw Error.get(QueryConstants.ERR_INVALID_SET_EXPRESSION, node.toString()); } SetExpression(UpdateOperator op, List<FieldAndRValue> list);  SetExpression(UpdateOperator op, FieldAndRValue... l); }
SetExpression extends PrimitiveUpdateExpression { public static SetExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = null; if (node.has(UpdateOperator._add.toString())) { op = UpdateOperator._add; } else if (node.has(UpdateOperator._set.toString())) { op = UpdateOperator._set; } if (op != null) { ObjectNode arg = (ObjectNode) node.get(op.toString()); List<FieldAndRValue> list = new ArrayList<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = arg.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); Path field = new Path(entry.getKey()); RValueExpression rvalue = RValueExpression.fromJson(entry.getValue()); list.add(new FieldAndRValue(field, rvalue)); } return new SetExpression(op, list); } } throw Error.get(QueryConstants.ERR_INVALID_SET_EXPRESSION, node.toString()); } SetExpression(UpdateOperator op, List<FieldAndRValue> list);  SetExpression(UpdateOperator op, FieldAndRValue... l); List<FieldAndRValue> getFields(); UpdateOperator getOp(); @Override JsonNode toJson(); static SetExpression fromJson(ObjectNode node); @Override int hashCode(); @Override boolean equals(Object obj); }
SetExpression extends PrimitiveUpdateExpression { public static SetExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = null; if (node.has(UpdateOperator._add.toString())) { op = UpdateOperator._add; } else if (node.has(UpdateOperator._set.toString())) { op = UpdateOperator._set; } if (op != null) { ObjectNode arg = (ObjectNode) node.get(op.toString()); List<FieldAndRValue> list = new ArrayList<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = arg.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); Path field = new Path(entry.getKey()); RValueExpression rvalue = RValueExpression.fromJson(entry.getValue()); list.add(new FieldAndRValue(field, rvalue)); } return new SetExpression(op, list); } } throw Error.get(QueryConstants.ERR_INVALID_SET_EXPRESSION, node.toString()); } SetExpression(UpdateOperator op, List<FieldAndRValue> list);  SetExpression(UpdateOperator op, FieldAndRValue... l); List<FieldAndRValue> getFields(); UpdateOperator getOp(); @Override JsonNode toJson(); static SetExpression fromJson(ObjectNode node); @Override int hashCode(); @Override boolean equals(Object obj);  }