@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
return boolean.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type); if (node.isObject() || node.isPojo()) { return !type.isPrimitive() && !String.class.isAssignableFrom(type) && !Number.class.isAssignableFrom(type) && !Boolean.class.isAssignableFrom(type);
@Override public boolean isExpandedNodeField(String fieldKey) { JsonNode field = node.get(fieldKey); if (field == null) { return false; } if (field.isObject() && field.has("fields")) { return true; } if (field.isPojo()) { return ((POJONode) field).getPojo() instanceof NodeResponse; } return false; }
private static <T> T toValue(ObjectCodec codec, JsonNode node, Class<T> valueType) throws JsonProcessingException { if (node.isPojo()) { Object pojo = ((POJONode) node).getPojo(); if (valueType.isInstance(pojo)) { return valueType.cast(pojo); } } return codec.treeToValue(node, valueType); }
private BinaryField transformBinaryFieldJsonNode(JsonNode jsonNode, String key) throws JsonProcessingException { // Unwrap stored pojos if (jsonNode.isPojo()) { return pojoNodeToValue(jsonNode, BinaryField.class, key); } return JsonUtil.getMapper().treeToValue(jsonNode, BinaryFieldImpl.class); }
private StringField transformStringFieldJsonNode(JsonNode jsonNode, String key) throws JsonProcessingException { // Unwrap stored pojos if (jsonNode.isPojo()) { StringField field = pojoNodeToValue(jsonNode, StringField.class, key); if (field == null || field.getString() == null) { return null; } else { return field; } } StringField stringField = new StringFieldImpl(); if (!jsonNode.isNull() && jsonNode.isTextual()) { stringField.setString(jsonNode.textValue()); } if (!jsonNode.isNull() && !jsonNode.isTextual()) { throw error(BAD_REQUEST, "The field value for {" + key + "} is not a text value. The value was {" + jsonNode.asText() + "}"); } return stringField; }
/** * Transform the JSON node field into html field POJO. * * @param jsonNode * @param key * @return */ private HtmlField transformHtmlFieldJsonNode(JsonNode jsonNode, String key) { // Unwrap stored pojos if (jsonNode.isPojo()) { HtmlField field = pojoNodeToValue(jsonNode, HtmlField.class, key); if (field == null || field.getHTML() == null) { return null; } else { return field; } } HtmlField htmlField = new HtmlFieldImpl(); if (!jsonNode.isNull() && jsonNode.isTextual()) { htmlField.setHTML(jsonNode.textValue()); } if (!jsonNode.isNull() && !jsonNode.isTextual()) { throw error(BAD_REQUEST, "field_html_error_invalid_type", key, jsonNode.asText()); } return htmlField; }
/** * Transform the JSON node into a response POJO. * * @param jsonNode * @param key * @return */ private DateField transformDateFieldJsonNode(JsonNode jsonNode, String key) { // Unwrap stored pojos if (jsonNode.isPojo()) { DateField field = pojoNodeToValue(jsonNode, DateField.class, key); if (field == null || field.getDate() == null) { return null; } else { return field; } } DateField dateField = new DateFieldImpl(); if (!jsonNode.isNull() && jsonNode.isTextual()) { dateField.setDate(jsonNode.textValue()); } if (!jsonNode.isNull() && !jsonNode.isTextual()) { throw error(BAD_REQUEST, "The field value for date field {" + key + "} is not a string value. The value was {" + jsonNode.asText() + "}"); } return dateField; }
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException { // Multiple possibilities... JsonNode n = currentNode(); if (n != null) { // binary node? byte[] data = n.binaryValue(); // (or TextNode, which can also convert automatically!) if (data != null) { return data; } // Or maybe byte[] as POJO? if (n.isPojo()) { Object ob = ((POJONode) n).getPojo(); if (ob instanceof byte[]) { return (byte[]) ob; } } } // otherwise return null to mark we have no binary content return null; }
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException { // Multiple possibilities... JsonNode n = currentNode(); if (n != null) { // binary node? byte[] data = n.binaryValue(); // (or TextNode, which can also convert automatically!) if (data != null) { return data; } // Or maybe byte[] as POJO? if (n.isPojo()) { Object ob = ((POJONode) n).getPojo(); if (ob instanceof byte[]) { return (byte[]) ob; } } } // otherwise return null to mark we have no binary content return null; }
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException { // Multiple possibilities... JsonNode n = currentNode(); if (n != null) { // binary node? byte[] data = n.binaryValue(); // (or TextNode, which can also convert automatically!) if (data != null) { return data; } // Or maybe byte[] as POJO? if (n.isPojo()) { Object ob = ((POJONode) n).getPojo(); if (ob instanceof byte[]) { return (byte[]) ob; } } } // otherwise return null to mark we have no binary content return null; }
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException { // Multiple possibilities... JsonNode n = currentNode(); if (n != null) { // binary node? byte[] data = n.binaryValue(); // (or TextNode, which can also convert automatically!) if (data != null) { return data; } // Or maybe byte[] as POJO? if (n.isPojo()) { Object ob = ((POJONode) n).getPojo(); if (ob instanceof byte[]) { return (byte[]) ob; } } } // otherwise return null to mark we have no binary content return null; }
@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
@Override public void serializeWithType(Atom value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { final JsonNode atom = value.asAtom(); if (atom == null || atom.isObject() || atom.isPojo() || atom.isArray() || value.getExpires() != null) { typeSer.writeTypePrefixForObject(value, gen); if (atom != null) { gen.writeObjectField("value", value.asAtom()); } if (value.getExpires() != null) { gen.writeObjectField("$expires", value.getExpires()); } typeSer.writeTypeSuffixForObject(value, gen); } else { // Omit type if atom is not an object gen.writeTree(value.asAtom()); } } }
@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
@Override public Object getEmbeddedObject() { if (!_closed) { JsonNode n = currentNode(); if (n != null) { if (n.isPojo()) { return ((POJONode) n).getPojo(); } if (n.isBinary()) { return ((BinaryNode) n).binaryValue(); } } } return null; }
private NumberField transformNumberFieldJsonNode(JsonNode jsonNode, String key) { // Unwrap stored pojos if (jsonNode.isPojo()) { NumberField field = pojoNodeToValue(jsonNode, NumberField.class, key); if (field == null || field.getNumber() == null) { return null; } else { return field; } } NumberField numberField = new NumberFieldImpl(); if (!jsonNode.isNull() && jsonNode.isNumber()) { Number number = jsonNode.numberValue(); numberField.setNumber(number); } if (!jsonNode.isNull() && !jsonNode.isNumber()) { throw error(BAD_REQUEST, "field_number_error_invalid_type", key, jsonNode.asText()); } return numberField; }