src/main/java/com/cedarsoftware/util/io/MapResolver.java
protected void traverseCollection(final Deque<JsonObject<String, Object>> stack, final JsonObject<String, Object> jsonObj)
    {
        final Object[] items = jsonObj.getArray();
        if (items == null || items.length == 0)
        {
            return;
        }

        int idx = 0;
        final List copy = new ArrayList(items.length);

        for (Object element : items)
        {
            if (element == JsonParser.EMPTY_OBJECT)
            {
                copy.add(new JsonObject());
                continue;
            }

            copy.add(element);

            if (element instanceof Object[])
            {   // array element inside Collection
                JsonObject<String, Object> jsonObject = new JsonObject<String, Object>();
                jsonObject.put("@items", element);
                stack.addFirst(jsonObject);
            }
            else if (element instanceof JsonObject)
            {
                JsonObject<String, Object> jsonObject = (JsonObject<String, Object>) element;
                Long refId = jsonObject.getReferenceId();

                if (refId != null)
                {    // connect reference
                    JsonObject refObject = getReferencedObj(refId);
                    copy.set(idx, refObject);
                }
                else
                {
                    stack.addFirst(jsonObject);
                }
            }
            idx++;
        }
        jsonObj.target = null;  // don't waste space (used for typed return, not generic Map return)

        for (int i=0; i < items.length; i++)
        {
            items[i] = copy.get(i);
        }
    }
protected void traverseCollection(final Deque<JsonObject<String, Object>> stack, final JsonObject<String, Object> jsonObj)
    {
        final Object[] items = jsonObj.getArray();
        if (items == null || items.length == 0)
        {
            return;
        }

        int idx = 0;
        final List copy = new ArrayList(items.length);

        for (Object element : items)
        {
            if (element == JsonParser.EMPTY_OBJECT)
            {
                copy.add(new JsonObject());
                continue;
            }

            copy.add(element);

            if (element instanceof Object[])
            {   // array element inside Collection
                JsonObject<String, Object> jsonObject = new JsonObject<String, Object>();
                jsonObject.put("@items", element);
                stack.addFirst(jsonObject);
            }
            else if (element instanceof JsonObject)
            {
                JsonObject<String, Object> jsonObject = (JsonObject<String, Object>) element;
                Long refId = jsonObject.getReferenceId();

                if (refId != null)
                {    // connect reference
                    JsonObject refObject = getReferencedObj(refId);
                    copy.set(idx, refObject);
                }
                else
                {
                    stack.addFirst(jsonObject);
                }
            }
            idx++;
        }
        jsonObj.target = null;  // don't waste space (used for typed return, not generic Map return)

        for (int i=0; i < items.length; i++)
        {
            items[i] = copy.get(i);
        }
    }
protected void traverseCollection ( final Deque < JsonObject < String , Object > > stack , final JsonObject < String , Object > jsonObj ) { final Object [ ] items = jsonObj . getArray ( ) ; if ( items == null || items . length == 0 ) { return ; } int idx = 0 ; final List copy = new ArrayList ( items . length ) ; for ( Object element : items ) { if ( element == JsonParser . EMPTY_OBJECT ) { copy . add ( new JsonObject ( ) ) ; continue ; } copy . add ( element ) ; if ( element instanceof Object [ ] ) { // array element inside Collection JsonObject < String , Object > jsonObject = new JsonObject < String , Object > ( ) ; jsonObject . put ( "@items" , element ) ; stack . addFirst ( jsonObject ) ; } else if ( element instanceof JsonObject ) { JsonObject < String , Object > jsonObject = ( JsonObject < String , Object > ) element ; Long refId = jsonObject . getReferenceId ( ) ; if ( refId != null ) { // connect reference JsonObject refObject = getReferencedObj ( refId ) ; copy . set ( idx , refObject ) ; } else { stack . addFirst ( jsonObject ) ; } } idx ++ ; } jsonObj . target = null ; // don't waste space (used for typed return, not generic Map return) for ( int i = 0 ; i < items . length ; i ++ ) { items [ i ] = copy . get ( i ) ; } }
Process java.util.Collection and it's derivatives.  Collections are written specially
so that the serialization does not expose the Collection's internal structure, for
example a TreeSet.  All entries are processed, except unresolved references, which
are filled in later.  For an indexable collection, the unresolved references are set
back into the proper element location.  For non-indexable collections (Sets), the
unresolved references are added via .add().
@param stack   a Stack (Deque) used to support graph traversal.
@param jsonObj a Map-of-Map representation of the JSON input stream.
Process java . util . Collection and it s derivatives . Collections are written specially so that the serialization does not expose the Collection s internal structure for example a TreeSet . All entries are processed except unresolved references which are filled in later . For an indexable collection the unresolved references are set back into the proper element location . For non - indexable collections ( Sets ) the unresolved references are added via . add () .