Refine search
@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; }
/** * Factory method for constructing a wrapper for POJO * ("Plain Old Java Object") objects; these will get serialized * using data binding, usually as JSON Objects, but in some * cases as JSON Strings or other node types. */ @Override public ValueNode pojoNode(Object pojo) { return new POJONode(pojo); }
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o instanceof POJONode) { return _pojoEquals((POJONode) o); } return false; }
return valueNode.asText(); } else if (valueNode instanceof BooleanNode) { return valueNode.asBoolean(); } else if (valueNode instanceof DoubleNode || valueNode instanceof FloatNode) { return valueNode.asDouble(); } else if (valueNode instanceof IntNode) { return valueNode.asInt(); } else if (valueNode instanceof POJONode) { POJONode pojoNode = (POJONode) valueNode; return pojoNode.getPojo(); } else if (valueNode instanceof ArrayNode) { ArrayNode arrayNode = (ArrayNode) valueNode;
@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; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Check that it's a JSON-RPC method MethodMetadata methodMetadata = classMetadata.getMethods().get(method); if (methodMetadata == null) { throw new IllegalStateException("Method '" + method.getName() + "' is not JSON-RPC available"); } // Get method name (annotation or the actual name), params and id generator String methodName = methodMetadata.getName(); JsonNode params = getParams(methodMetadata, args, getParamsType(classMetadata, methodMetadata)); IdGenerator<?> idGenerator = userIdGenerator != null ? userIdGenerator : classMetadata.getIdGenerator(); // Construct a request ValueNode id = new POJONode(idGenerator.generate()); String textResponse = execute(request(id, methodName, params)); // Parse a response JsonNode responseNode = mapper.readTree(textResponse); JsonNode result = responseNode.get(RESULT); JsonNode error = responseNode.get(ERROR); if (result != null) { JavaType returnType = mapper.getTypeFactory().constructType(method.getGenericReturnType()); if (returnType.getRawClass() == void.class) { return null; } return mapper.convertValue(result, returnType); } else { ErrorMessage errorMessage = mapper.treeToValue(error, ErrorMessage.class); throw new JsonRpcException(errorMessage); } }
@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; }
Object ob = ((POJONode) n).getPojo(); if ((ob == null) || valueType.isInstance(ob)) { return (T) ob;
return valueNode.asText(); } else if (valueNode instanceof BooleanNode) { return valueNode.asBoolean(); } else if (valueNode instanceof DoubleNode || valueNode instanceof FloatNode) { return valueNode.asDouble(); } else if (valueNode instanceof IntNode) { return valueNode.asInt(); } else if (valueNode instanceof POJONode) { POJONode pojoNode = (POJONode) valueNode; return pojoNode.getPojo(); } else if (valueNode instanceof ArrayNode) { ArrayNode arrayNode = (ArrayNode) valueNode;
@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; }
/** * Unwrapped the POJO within the JSON node. * * @param jsonNode * @param clazz * @param key * @return */ private <T extends Field> T pojoNodeToValue(JsonNode jsonNode, Class<T> clazz, String key) { Object pojo = ((POJONode) jsonNode).getPojo(); if (pojo == null) { return null; } if (clazz.isAssignableFrom(pojo.getClass())) { return clazz.cast(pojo); } else { throw error(BAD_REQUEST, "The field value for {" + key + "} is not of correct type. Stored POJO was of class {" + pojo.getClass() .getName() + "}"); } }
@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; }
Object ob = ((POJONode) n).getPojo(); if ((ob == null) || valueType.isInstance(ob)) { return (T) ob;
@Override public ValueNode rawValueNode(RawValue value) { return new POJONode(value); }
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o instanceof POJONode) { return _pojoEquals((POJONode) o); } return false; }
@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; }