/** * Parses out included resources excluding relationships. * @param parent root node * @return map of identifier/resource pairs * @throws IOException * @throws IllegalAccessException * @throws InstantiationException */ private Map<String, Object> getIncludedResources(JsonNode parent) throws IOException, IllegalAccessException, InstantiationException { Map<String, Object> result = new HashMap<>(); if (parent.has(INCLUDED)) { for (JsonNode jsonNode : parent.get(INCLUDED)) { String type = jsonNode.get(TYPE).asText(); Class<?> clazz = configuration.getTypeClass(type); if (clazz != null) { Object object = readObject(jsonNode, clazz, false); if (object != null) { result.put(createIdentifier(jsonNode), object); } } else if (!deserializationFeatures.contains(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS)) { throw new IllegalArgumentException("Included section contains unknown resource type: " + type); } } } return result; }
/** * Parses out included resources excluding relationships. * @param parent root node * @return map of identifier/resource pairs * @throws IOException * @throws IllegalAccessException * @throws InstantiationException */ private Map<String, Object> getIncludedResources(JsonNode parent) throws IOException, IllegalAccessException, InstantiationException { Map<String, Object> result = new HashMap<>(); if (parent.has(INCLUDED)) { for (JsonNode jsonNode : parent.get(INCLUDED)) { String type = jsonNode.get(TYPE).asText(); Class<?> clazz = configuration.getTypeClass(type); if (clazz != null) { Object object = readObject(jsonNode, clazz, false); if (object != null) { result.put(createIdentifier(jsonNode), object); } } else if (!deserializationFeatures.contains(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS)) { throw new IllegalArgumentException("Included section contains unknown resource type: " + type); } } } return result; }
T pojo = readObject(element, clazz, false); resourceList.add(pojo);
T pojo = readObject(element, clazz, false); resourceList.add(pojo);
resourceObject = (T) resourceCache.get(identifier); } else { resourceObject = readObject(dataNode, clazz, false);
resourceObject = (T) resourceCache.get(identifier); } else { resourceObject = readObject(dataNode, clazz, false);
/** * Creates relationship object by consuming provided 'data' node. * @param relationshipDataNode relationship data node * @param type object type * @return created object or <code>null</code> in case data node is not valid * @throws IOException * @throws IllegalAccessException * @throws InstantiationException */ private Object parseRelationship(JsonNode relationshipDataNode, Class<?> type) throws IOException, IllegalAccessException, InstantiationException { if (ValidationUtils.isRelationshipParsable(relationshipDataNode)) { String identifier = createIdentifier(relationshipDataNode); if (resourceCache.contains(identifier)) { return resourceCache.get(identifier); } else { // Never cache relationship objects resourceCache.lock(); try { return readObject(relationshipDataNode, type, true); } finally { resourceCache.unlock(); } } } return null; }
/** * Creates relationship object by consuming provided 'data' node. * @param relationshipDataNode relationship data node * @param type object type * @return created object or <code>null</code> in case data node is not valid * @throws IOException * @throws IllegalAccessException * @throws InstantiationException */ private Object parseRelationship(JsonNode relationshipDataNode, Class<?> type) throws IOException, IllegalAccessException, InstantiationException { if (ValidationUtils.isRelationshipParsable(relationshipDataNode)) { String identifier = createIdentifier(relationshipDataNode); if (resourceCache.contains(identifier)) { return resourceCache.get(identifier); } else { // Never cache relationship objects resourceCache.lock(); try { return readObject(relationshipDataNode, type, true); } finally { resourceCache.unlock(); } } } return null; }