private static CollectionModel<?> extractResources(UberDocument doc, JavaType rootType, JavaType contentType) {

		List<Object> content = new ArrayList<>();

		for (UberData uberData : doc.getUber().getData()) {

			String name = uberData.getName();

			if (name != null && name.equals("page")) {
				continue;
			}

			if (!uberData.getLinks().isEmpty()) {
				continue;
			}

			List<Link> resourceLinks = new ArrayList<>();
			EntityModel<?> resource = null;

			List<UberData> data = uberData.getData();

			if (data == null) {
				throw new RuntimeException("No content!");
			}

			for (UberData item : data) {

				List<LinkRelation> rel = item.getRel();

				if (rel != null) {
					item.getLinks().forEach(resourceLinks::add);
				} else {

					// Primitive type
					List<UberData> itemData = item.getData();

					if (isPrimitiveType(itemData)) {

						if (itemData == null) {
							throw new IllegalStateException();
						}

						UberData firstItem = itemData.get(0);
						Object scalarValue = firstItem.getValue();
						resource = new EntityModel<>(scalarValue, uberData.getLinks());

					} else {

						Map<String, Object> properties = itemData == null //
								? new HashMap<>() //
								: itemData.stream() //
										.collect(Collectors.toMap(UberData::getName, UberData::getValue));

						Object obj = PropertyUtils.createObjectFromProperties(rootType.getRawClass(), properties);
						resource = new EntityModel<>(obj, uberData.getLinks());
					}
				}
			}

			if (resource != null) {

				resource.add(resourceLinks);
				content.add(resource);
			} else {
				throw new RuntimeException("No content!");
			}
		}

		if (isResourcesOfResource(contentType)) {
			/*
			 * Either return a Resources<Resource<T>>...
			 */
			return new CollectionModel<>(content, doc.getUber().getLinks());
		} else {
			/*
			 * ...or return a Resources<T>
			 */

			List<Object> resourceLessContent = content.stream().map(item -> (EntityModel<?>) item)
					.map(EntityModel::getContent).collect(Collectors.toList());

			return new CollectionModel<>(resourceLessContent, doc.getUber().getLinks());
		}
	}
private static CollectionModel < ? > extractResources ( UberDocument doc , JavaType rootType , JavaType contentType ) { List < Object > content = new ArrayList < > ( ) ; for ( UberData uberData : doc . getUber ( ) . getData ( ) ) { String name = uberData . getName ( ) ; if ( name != null && name . equals ( "page" ) ) { continue ; } if ( ! uberData . getLinks ( ) . isEmpty ( ) ) { continue ; } List < Link > resourceLinks = new ArrayList < > ( ) ; EntityModel < ? > resource = null ; List < UberData > data = uberData . getData ( ) ; if ( data == null ) { throw new RuntimeException ( "No content!" ) ; } for ( UberData item : data ) { List < LinkRelation > rel = item . getRel ( ) ; if ( rel != null ) { item . getLinks ( ) . forEach ( resourceLinks :: add ) ; } else { List < UberData > itemData = item . getData ( ) ; if ( isPrimitiveType ( itemData ) ) { if ( itemData == null ) { throw new IllegalStateException ( ) ; } UberData firstItem = itemData . get ( 0 ) ; Object scalarValue = firstItem . getValue ( ) ; resource = new EntityModel < > ( scalarValue , uberData . getLinks ( ) ) ; } else { Map < String , Object > properties = itemData == null ? new HashMap < > ( ) : itemData . stream ( ) . collect ( Collectors . toMap ( UberData :: getName , UberData :: getValue ) ) ; Object obj = PropertyUtils . createObjectFromProperties ( rootType . getRawClass ( ) , properties ) ; resource = new EntityModel < > ( obj , uberData . getLinks ( ) ) ; } } } if ( resource != null ) { resource . add ( resourceLinks ) ; content . add ( resource ) ; } else { throw new RuntimeException ( "No content!" ) ; } } if ( isResourcesOfResource ( contentType ) ) { return new CollectionModel < > ( content , doc . getUber ( ) . getLinks ( ) ) ; } else { List < Object > resourceLessContent = content . stream ( ) . map ( item -> ( EntityModel < ? > ) item ) . map ( EntityModel :: getContent ) . collect ( Collectors . toList ( ) ) ; return new CollectionModel < > ( resourceLessContent , doc . getUber ( ) . getLinks ( ) ) ; } }
Convert an {@link UberDocument} into a {@link CollectionModel}.

@param doc
@param rootType
@param contentType
@return