src/main/java/com/cedarsoftware/util/io/ObjectResolver.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;
        }
        final Collection col = (Collection) jsonObj.target;
        final boolean isList = col instanceof List;
        int idx = 0;

        for (final Object element : items)
        {
            Object special;
            if (element == null)
            {
                col.add(null);
            }
            else if (element == JsonParser.EMPTY_OBJECT)
            {   // Handles {}
                col.add(new JsonObject());
            }
            else if ((special = readIfMatching(element, null, stack)) != null)
            {
                col.add(special);
            }
            else if (element instanceof String || element instanceof Boolean || element instanceof Double || element instanceof Long)
            {    // Allow Strings, Booleans, Longs, and Doubles to be "inline" without Java object decoration (@id, @type, etc.)
                col.add(element);
            }
            else if (element.getClass().isArray())
            {
                final JsonObject jObj = new JsonObject();
                jObj.put("@items", element);
                createJavaObjectInstance(Object.class, jObj);
                col.add(jObj.target);
                convertMapsToObjects(jObj);
            }
            else // if (element instanceof JsonObject)
            {
                final JsonObject jObj = (JsonObject) element;
                final Long ref = jObj.getReferenceId();

                if (ref != null)
                {
                    JsonObject refObject = getReferencedObj(ref);

                    if (refObject.target != null)
                    {
                        col.add(refObject.target);
                    }
                    else
                    {
                        unresolvedRefs.add(new UnresolvedReference(jsonObj, idx, ref));
                        if (isList)
                        {   // Indexable collection, so set 'null' as element for now - will be patched in later.
                            col.add(null);
                        }
                    }
                }
                else
                {
                    createJavaObjectInstance(Object.class, jObj);

                    if (!MetaUtils.isLogicalPrimitive(jObj.getTargetClass()))
                    {
                        convertMapsToObjects(jObj);
                    }
                    col.add(jObj.target);
                }
            }
            idx++;
        }

        jsonObj.remove("@items");   // Reduce memory required during processing
    }
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;
        }
        final Collection col = (Collection) jsonObj.target;
        final boolean isList = col instanceof List;
        int idx = 0;

        for (final Object element : items)
        {
            Object special;
            if (element == null)
            {
                col.add(null);
            }
            else if (element == JsonParser.EMPTY_OBJECT)
            {   // Handles {}
                col.add(new JsonObject());
            }
            else if ((special = readIfMatching(element, null, stack)) != null)
            {
                col.add(special);
            }
            else if (element instanceof String || element instanceof Boolean || element instanceof Double || element instanceof Long)
            {    // Allow Strings, Booleans, Longs, and Doubles to be "inline" without Java object decoration (@id, @type, etc.)
                col.add(element);
            }
            else if (element.getClass().isArray())
            {
                final JsonObject jObj = new JsonObject();
                jObj.put("@items", element);
                createJavaObjectInstance(Object.class, jObj);
                col.add(jObj.target);
                convertMapsToObjects(jObj);
            }
            else // if (element instanceof JsonObject)
            {
                final JsonObject jObj = (JsonObject) element;
                final Long ref = jObj.getReferenceId();

                if (ref != null)
                {
                    JsonObject refObject = getReferencedObj(ref);

                    if (refObject.target != null)
                    {
                        col.add(refObject.target);
                    }
                    else
                    {
                        unresolvedRefs.add(new UnresolvedReference(jsonObj, idx, ref));
                        if (isList)
                        {   // Indexable collection, so set 'null' as element for now - will be patched in later.
                            col.add(null);
                        }
                    }
                }
                else
                {
                    createJavaObjectInstance(Object.class, jObj);

                    if (!MetaUtils.isLogicalPrimitive(jObj.getTargetClass()))
                    {
                        convertMapsToObjects(jObj);
                    }
                    col.add(jObj.target);
                }
            }
            idx++;
        }

        jsonObj.remove("@items");   // Reduce memory required during processing
    }
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 ; } final Collection col = ( Collection ) jsonObj . target ; final boolean isList = col instanceof List ; int idx = 0 ; for ( final Object element : items ) { Object special ; if ( element == null ) { col . add ( null ) ; } else if ( element == JsonParser . EMPTY_OBJECT ) { // Handles {} col . add ( new JsonObject ( ) ) ; } else if ( ( special = readIfMatching ( element , null , stack ) ) != null ) { col . add ( special ) ; } else if ( element instanceof String || element instanceof Boolean || element instanceof Double || element instanceof Long ) { // Allow Strings, Booleans, Longs, and Doubles to be "inline" without Java object decoration (@id, @type, etc.) col . add ( element ) ; } else if ( element . getClass ( ) . isArray ( ) ) { final JsonObject jObj = new JsonObject ( ) ; jObj . put ( "@items" , element ) ; createJavaObjectInstance ( Object . class , jObj ) ; col . add ( jObj . target ) ; convertMapsToObjects ( jObj ) ; } else // if (element instanceof JsonObject) { final JsonObject jObj = ( JsonObject ) element ; final Long ref = jObj . getReferenceId ( ) ; if ( ref != null ) { JsonObject refObject = getReferencedObj ( ref ) ; if ( refObject . target != null ) { col . add ( refObject . target ) ; } else { unresolvedRefs . add ( new UnresolvedReference ( jsonObj , idx , ref ) ) ; if ( isList ) { // Indexable collection, so set 'null' as element for now - will be patched in later. col . add ( null ) ; } } } else { createJavaObjectInstance ( Object . class , jObj ) ; if ( ! MetaUtils . isLogicalPrimitive ( jObj . getTargetClass ( ) ) ) { convertMapsToObjects ( jObj ) ; } col . add ( jObj . target ) ; } } idx ++ ; } jsonObj . remove ( "@items" ) ; // Reduce memory required during processing }
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 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 () .