private <T extends HalRepresentation> List<T> traverseInitialResource(final Class<T> resultType,
                                                                          final List<EmbeddedTypeInfo> embeddedTypeInfo,
                                                                          final boolean retrieveAll) throws IOException {
        /*
        #hops = N; N > 0
        max nesting-level in embeddedTypeInfo = M; M >= 0
        */
        final Link initial = self(startWith.toString());
        LOG.trace("Starting with {}", startWith);
        this.startWith = null;
        if (hops.isEmpty()) {
            /*
            0. N=0, M=0:
            getResource(startwith, pageType)
            */
            return singletonList(
                    getResource(initial, resultType, embeddedTypeInfo)
            );
        } else {
            final HalRepresentation firstHop;
            // Follow startWith URL, but have a look at the next hop, so we can parse the resource
            // with respect to pageType and embeddedTypeInfo:
            if (hops.size() == 1) {
                final Hop hop = hops.get(0);
                if (embeddedTypeInfo == null || embeddedTypeInfo.isEmpty()) {
                    /*
                    1. N=1, M=0 (keine TypeInfos):
                    Die zurückgegebene Representation soll vom Typ resultType sein.

                    startWith könnte hop 0 embedden, oder es könnten zwei Resourcen angefragt werden.

                    a) getResource(startwith, HalRepresentation.class, embeddedTypeInfo(hop-0-rel, pageType))
                    b) getResource(current, pageType)
                    */
                    firstHop = getResource(initial, HalRepresentation.class, withEmbedded(hop.rel, resultType));
                } else {
                    /*
                    2. N=1, M>0 (mit TypeInfos)
                    Die zurückgegebene Representation soll vom Typ pageType sein und eingebettete Items gemäss der embeddedTypeInfo enthalten.

                    startWith könnte hop 0 embedden, oder es könnten zwei Resourcen angefragt werden.

                    a) getResource(startwith, HalRepresentation.class, embeddedTypeInfo(hop-0-rel, pageType, embeddedTypeInfo))
                    b) getResource(current, pageType, embeddedTypeInfo)
                    */
                    //firstHop = getResource(current, pageType, embeddedTypeInfo);
                    firstHop = getResource(initial, HalRepresentation.class, withEmbedded(hop.rel, resultType, embeddedTypeInfo));
                }
            } else {
                /*
                3. N>=2, M=0
                Die zurückgegebene Representation soll vom Typ pageType sein.

                startWith könnte hop 0 und 1 embedden, oder es könnten zwei Resourcen angefragt werden, von denen die zweite
                den hop 1 embedded, oder es könnten drei Resource angefragt werden.

                a) getResource(startWith, HalRepresentation.class, embeddedTypeInfo(hop-0-rel, HalRepresentation.class, hop-1-rel, pageType,)
                b) getResource(current, HalRepresentation.class, embeddedTypeInfo(hop-1-rel, pageType)
                c) getResource(current, pageType)
                */
                firstHop = getResource(initial, HalRepresentation.class, embeddedTypeInfoFor(hops, resultType, embeddedTypeInfo));
            }
            return traverseHop(firstHop, resultType, embeddedTypeInfo, retrieveAll);
        }
    }
private < T extends HalRepresentation > List < T > traverseInitialResource ( final Class < T > resultType , final List < EmbeddedTypeInfo > embeddedTypeInfo , final boolean retrieveAll ) throws IOException { final Link initial = self ( startWith . toString ( ) ) ; LOG . trace ( "Starting with {}" , startWith ) ; this . startWith = null ; if ( hops . isEmpty ( ) ) { return singletonList ( getResource ( initial , resultType , embeddedTypeInfo ) ) ; } else { final HalRepresentation firstHop ; if ( hops . size ( ) == 1 ) { final Hop hop = hops . get ( 0 ) ; if ( embeddedTypeInfo == null || embeddedTypeInfo . isEmpty ( ) ) { firstHop = getResource ( initial , HalRepresentation . class , withEmbedded ( hop . rel , resultType ) ) ; } else { firstHop = getResource ( initial , HalRepresentation . class , withEmbedded ( hop . rel , resultType , embeddedTypeInfo ) ) ; } } else { firstHop = getResource ( initial , HalRepresentation . class , embeddedTypeInfoFor ( hops , resultType , embeddedTypeInfo ) ) ; } return traverseHop ( firstHop , resultType , embeddedTypeInfo , retrieveAll ) ; } }
@param resultType the Class of the returned HalRepresentation.
@param embeddedTypeInfo type information about embedded items
@param retrieveAll false if only a single resource is returned, true otherwise.
@param <T> type parameter of the returned HalRepresentation
@return list of zero or more HalRepresentations.
@throws IOException if a low-level I/O problem (unexpected end-of-input, network error) occurs.
@throws JsonParseException if the json document can not be parsed by Jackson's ObjectMapper
@throws JsonMappingException if the input JSON structure can not be mapped to the specified HalRepresentation type