public <T> JSONAPIDocument<List<T>> readDocumentCollection(InputStream dataStream, Class<T> clazz) {
		try {
			resourceCache.init();

			JsonNode rootNode = objectMapper.readTree(dataStream);

			// Validate
			ValidationUtils.ensureNotError(objectMapper, rootNode);
			ValidationUtils.ensureValidResource(rootNode);

			JsonNode dataNode = rootNode.get(DATA);

			// Parse data node without handling relationships
			List<T> resourceList = new ArrayList<>();

			if (dataNode != null && dataNode.isArray()) {
				for (JsonNode element : dataNode) {
					T pojo = readObject(element, clazz, false);
					resourceList.add(pojo);
				}
			}

			// Parse all included resources
			resourceCache.cache(parseIncluded(rootNode));

			// Connect data node's relationships now that all resources have been parsed
			for (int i = 0; i < resourceList.size(); i++) {
				JsonNode source = dataNode != null && dataNode.isArray() ? dataNode.get(i) : null;
				T resourceObject = resourceList.get(i);
				if (source != null && resourceObject != null) {
					handleRelationships(source, resourceObject);
				}
			}

			JSONAPIDocument<List<T>> result = new JSONAPIDocument<>(resourceList, objectMapper);

			// Handle top-level meta
			if (rootNode.has(META)) {
				result.setMeta(mapMeta(rootNode.get(META)));
			}

			// Handle top-level links
			if (rootNode.has(LINKS)) {
				result.setLinks(new Links(mapLinks(rootNode.get(LINKS))));
			}

			return result;
		} catch (RuntimeException e) {
			throw e;
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			resourceCache.clear();
		}
	}
public < T > JSONAPIDocument < List < T > > readDocumentCollection ( InputStream dataStream , Class < T > clazz ) { try { resourceCache . init ( ) ; JsonNode rootNode = objectMapper . readTree ( dataStream ) ; ValidationUtils . ensureNotError ( objectMapper , rootNode ) ; ValidationUtils . ensureValidResource ( rootNode ) ; JsonNode dataNode = rootNode . get ( DATA ) ; List < T > resourceList = new ArrayList < > ( ) ; if ( dataNode != null && dataNode . isArray ( ) ) { for ( JsonNode element : dataNode ) { T pojo = readObject ( element , clazz , false ) ; resourceList . add ( pojo ) ; } } resourceCache . cache ( parseIncluded ( rootNode ) ) ; for ( int i = 0 ; i < resourceList . size ( ) ; i ++ ) { JsonNode source = dataNode != null && dataNode . isArray ( ) ? dataNode . get ( i ) : null ; T resourceObject = resourceList . get ( i ) ; if ( source != null && resourceObject != null ) { handleRelationships ( source , resourceObject ) ; } } JSONAPIDocument < List < T > > result = new JSONAPIDocument < > ( resourceList , objectMapper ) ; if ( rootNode . has ( META ) ) { result . setMeta ( mapMeta ( rootNode . get ( META ) ) ) ; } if ( rootNode . has ( LINKS ) ) { result . setLinks ( new Links ( mapLinks ( rootNode . get ( LINKS ) ) ) ) ; } return result ; } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { resourceCache . clear ( ) ; } }
Reads JSON API spec document and converts it into collection of target type objects.
@param dataStream {@link InputStream} input stream
@param clazz {@link Class} target type
@param <T> type
@return {@link JSONAPIDocument}