public <T>JSONAPIDocument<List<T>> readDocumentCollection(InputStream dataStream,Class<T> clazz){
  try {
    resourceCache.init();
    JsonNode rootNode=objectMapper.readTree(dataStream);
    ValidationUtils.ensureNotError(objectMapper,rootNode);
    ValidationUtils.ensureCollection(rootNode);
    resourceCache.cache(parseIncluded(rootNode));
    List<T> resourceList=new ArrayList<>();
    for (    JsonNode element : rootNode.get(DATA)) {
      T pojo=readObject(element,clazz,true);
      resourceList.add(pojo);
    }
    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();
  }
}

public < T > JSONAPIDocument < List < T > > readDocumentCollection ( InputStream dataStream , Class < T > clazz ) { try { resourceCache . init ( ) ; JsonNode rootNode = objectMapper . readTree ( dataStream ) ; ValidationUtils . ensureNotError ( objectMapper , rootNode ) ; ValidationUtils . ensureCollection ( rootNode ) ; resourceCache . cache ( parseIncluded ( rootNode ) ) ; List < T > resourceList = new ArrayList < > ( ) ; for ( JsonNode element : rootNode . get ( DATA ) ) { T pojo = readObject ( element , clazz , true ) ; resourceList . add ( pojo ) ; } 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 .
