src/main/java/com/cedarsoftware/util/io/ObjectResolver.java
protected void traverseArray(final Deque<JsonObject<String, Object>> stack, final JsonObject<String, Object> jsonObj)
    {
        final int len = jsonObj.getLength();
        if (len == 0)
        {
            return;
        }

        final Class compType = jsonObj.getComponentType();

        if (char.class == compType)
        {
            return;
        }

        if (byte.class == compType)
        {   // Handle byte[] special for performance boost.
            jsonObj.moveBytesToMate();
            jsonObj.clearArray();
            return;
        }

        final boolean isPrimitive = MetaUtils.isPrimitive(compType);
        final Object array = jsonObj.target;
        final Object[] items =  jsonObj.getArray();

        for (int i=0; i < len; i++)
        {
            final Object element = items[i];

            Object special;
            if (element == null)
            {
                Array.set(array, i, null);
            }
            else if (element == JsonParser.EMPTY_OBJECT)
            {    // Use either explicitly defined type in ObjectMap associated to JSON, or array component type.
                Object arrayElement = createJavaObjectInstance(compType, new JsonObject());
                Array.set(array, i, arrayElement);
            }
            else if ((special = readIfMatching(element, compType, stack)) != null)
            {
                Array.set(array, i, special);
            }
            else if (isPrimitive)
            {   // Primitive component type array
                Array.set(array, i, MetaUtils.convert(compType, element));
            }
            else if (element.getClass().isArray())
            {   // Array of arrays
                if (char[].class == compType)
                {   // Specially handle char[] because we are writing these
                    // out as UTF-8 strings for compactness and speed.
                    Object[] jsonArray = (Object[]) element;
                    if (jsonArray.length == 0)
                    {
                        Array.set(array, i, new char[]{});
                    }
                    else
                    {
                        final String value = (String) jsonArray[0];
                        final int numChars = value.length();
                        final char[] chars = new char[numChars];
                        for (int j = 0; j < numChars; j++)
                        {
                            chars[j] = value.charAt(j);
                        }
                        Array.set(array, i, chars);
                    }
                }
                else
                {
                    JsonObject<String, Object> jsonObject = new JsonObject<String, Object>();
                    jsonObject.put("@items", element);
                    Array.set(array, i, createJavaObjectInstance(compType, jsonObject));
                    stack.addFirst(jsonObject);
                }
            }
            else if (element instanceof JsonObject)
            {
                JsonObject<String, Object> jsonObject = (JsonObject<String, Object>) element;
                Long ref = jsonObject.getReferenceId();

                if (ref != null)
                {    // Connect reference
                    JsonObject refObject = getReferencedObj(ref);
                    if (refObject.target != null)
                    {   // Array element with reference to existing object
                        Array.set(array, i, refObject.target);
                    }
                    else
                    {    // Array with a forward reference as an element
                        unresolvedRefs.add(new UnresolvedReference(jsonObj, i, ref));
                    }
                }
                else
                {    // Convert JSON HashMap to Java Object instance and assign values
                    Object arrayElement = createJavaObjectInstance(compType, jsonObject);
                    Array.set(array, i, arrayElement);
                    if (!MetaUtils.isLogicalPrimitive(arrayElement.getClass()))
                    {    // Skip walking primitives, primitive wrapper classes, Strings, and Classes
                        stack.addFirst(jsonObject);
                    }
                }
            }
            else
            {
                if (element instanceof String && "".equals(((String) element).trim()) && compType != String.class && compType != Object.class)
                {   // Allow an entry of "" in the array to set the array element to null, *if* the array type is NOT String[] and NOT Object[]
                    Array.set(array, i, null);
                }
                else
                {
                    Array.set(array, i, element);
                }
            }
        }
        jsonObj.clearArray();
    }
protected void traverseArray(final Deque<JsonObject<String, Object>> stack, final JsonObject<String, Object> jsonObj)
    {
        final int len = jsonObj.getLength();
        if (len == 0)
        {
            return;
        }

        final Class compType = jsonObj.getComponentType();

        if (char.class == compType)
        {
            return;
        }

        if (byte.class == compType)
        {   // Handle byte[] special for performance boost.
            jsonObj.moveBytesToMate();
            jsonObj.clearArray();
            return;
        }

        final boolean isPrimitive = MetaUtils.isPrimitive(compType);
        final Object array = jsonObj.target;
        final Object[] items =  jsonObj.getArray();

        for (int i=0; i < len; i++)
        {
            final Object element = items[i];

            Object special;
            if (element == null)
            {
                Array.set(array, i, null);
            }
            else if (element == JsonParser.EMPTY_OBJECT)
            {    // Use either explicitly defined type in ObjectMap associated to JSON, or array component type.
                Object arrayElement = createJavaObjectInstance(compType, new JsonObject());
                Array.set(array, i, arrayElement);
            }
            else if ((special = readIfMatching(element, compType, stack)) != null)
            {
                Array.set(array, i, special);
            }
            else if (isPrimitive)
            {   // Primitive component type array
                Array.set(array, i, MetaUtils.convert(compType, element));
            }
            else if (element.getClass().isArray())
            {   // Array of arrays
                if (char[].class == compType)
                {   // Specially handle char[] because we are writing these
                    // out as UTF-8 strings for compactness and speed.
                    Object[] jsonArray = (Object[]) element;
                    if (jsonArray.length == 0)
                    {
                        Array.set(array, i, new char[]{});
                    }
                    else
                    {
                        final String value = (String) jsonArray[0];
                        final int numChars = value.length();
                        final char[] chars = new char[numChars];
                        for (int j = 0; j < numChars; j++)
                        {
                            chars[j] = value.charAt(j);
                        }
                        Array.set(array, i, chars);
                    }
                }
                else
                {
                    JsonObject<String, Object> jsonObject = new JsonObject<String, Object>();
                    jsonObject.put("@items", element);
                    Array.set(array, i, createJavaObjectInstance(compType, jsonObject));
                    stack.addFirst(jsonObject);
                }
            }
            else if (element instanceof JsonObject)
            {
                JsonObject<String, Object> jsonObject = (JsonObject<String, Object>) element;
                Long ref = jsonObject.getReferenceId();

                if (ref != null)
                {    // Connect reference
                    JsonObject refObject = getReferencedObj(ref);
                    if (refObject.target != null)
                    {   // Array element with reference to existing object
                        Array.set(array, i, refObject.target);
                    }
                    else
                    {    // Array with a forward reference as an element
                        unresolvedRefs.add(new UnresolvedReference(jsonObj, i, ref));
                    }
                }
                else
                {    // Convert JSON HashMap to Java Object instance and assign values
                    Object arrayElement = createJavaObjectInstance(compType, jsonObject);
                    Array.set(array, i, arrayElement);
                    if (!MetaUtils.isLogicalPrimitive(arrayElement.getClass()))
                    {    // Skip walking primitives, primitive wrapper classes, Strings, and Classes
                        stack.addFirst(jsonObject);
                    }
                }
            }
            else
            {
                if (element instanceof String && "".equals(((String) element).trim()) && compType != String.class && compType != Object.class)
                {   // Allow an entry of "" in the array to set the array element to null, *if* the array type is NOT String[] and NOT Object[]
                    Array.set(array, i, null);
                }
                else
                {
                    Array.set(array, i, element);
                }
            }
        }
        jsonObj.clearArray();
    }
protected void traverseArray ( final Deque < JsonObject < String , Object > > stack , final JsonObject < String , Object > jsonObj ) { final int len = jsonObj . getLength ( ) ; if ( len == 0 ) { return ; } final Class compType = jsonObj . getComponentType ( ) ; if ( char . class == compType ) { return ; } if ( byte . class == compType ) { // Handle byte[] special for performance boost. jsonObj . moveBytesToMate ( ) ; jsonObj . clearArray ( ) ; return ; } final boolean isPrimitive = MetaUtils . isPrimitive ( compType ) ; final Object array = jsonObj . target ; final Object [ ] items = jsonObj . getArray ( ) ; for ( int i = 0 ; i < len ; i ++ ) { final Object element = items [ i ] ; Object special ; if ( element == null ) { Array . set ( array , i , null ) ; } else if ( element == JsonParser . EMPTY_OBJECT ) { // Use either explicitly defined type in ObjectMap associated to JSON, or array component type. Object arrayElement = createJavaObjectInstance ( compType , new JsonObject ( ) ) ; Array . set ( array , i , arrayElement ) ; } else if ( ( special = readIfMatching ( element , compType , stack ) ) != null ) { Array . set ( array , i , special ) ; } else if ( isPrimitive ) { // Primitive component type array Array . set ( array , i , MetaUtils . convert ( compType , element ) ) ; } else if ( element . getClass ( ) . isArray ( ) ) { // Array of arrays if ( char [ ] . class == compType ) { // Specially handle char[] because we are writing these // out as UTF-8 strings for compactness and speed. Object [ ] jsonArray = ( Object [ ] ) element ; if ( jsonArray . length == 0 ) { Array . set ( array , i , new char [ ] { } ) ; } else { final String value = ( String ) jsonArray [ 0 ] ; final int numChars = value . length ( ) ; final char [ ] chars = new char [ numChars ] ; for ( int j = 0 ; j < numChars ; j ++ ) { chars [ j ] = value . charAt ( j ) ; } Array . set ( array , i , chars ) ; } } else { JsonObject < String , Object > jsonObject = new JsonObject < String , Object > ( ) ; jsonObject . put ( "@items" , element ) ; Array . set ( array , i , createJavaObjectInstance ( compType , jsonObject ) ) ; stack . addFirst ( jsonObject ) ; } } else if ( element instanceof JsonObject ) { JsonObject < String , Object > jsonObject = ( JsonObject < String , Object > ) element ; Long ref = jsonObject . getReferenceId ( ) ; if ( ref != null ) { // Connect reference JsonObject refObject = getReferencedObj ( ref ) ; if ( refObject . target != null ) { // Array element with reference to existing object Array . set ( array , i , refObject . target ) ; } else { // Array with a forward reference as an element unresolvedRefs . add ( new UnresolvedReference ( jsonObj , i , ref ) ) ; } } else { // Convert JSON HashMap to Java Object instance and assign values Object arrayElement = createJavaObjectInstance ( compType , jsonObject ) ; Array . set ( array , i , arrayElement ) ; if ( ! MetaUtils . isLogicalPrimitive ( arrayElement . getClass ( ) ) ) { // Skip walking primitives, primitive wrapper classes, Strings, and Classes stack . addFirst ( jsonObject ) ; } } } else { if ( element instanceof String && "" . equals ( ( ( String ) element ) . trim ( ) ) && compType != String . class && compType != Object . class ) { // Allow an entry of "" in the array to set the array element to null, *if* the array type is NOT String[] and NOT Object[] Array . set ( array , i , null ) ; } else { Array . set ( array , i , element ) ; } } } jsonObj . clearArray ( ) ; }
Traverse the JsonObject associated to an array (of any type).  Convert and
assign the list of items in the JsonObject (stored in the @items field)
to each array element.  All array elements are processed excluding elements
that reference an unresolved object.  These are filled in later.

@param stack   a Stack (Deque) used to support graph traversal.
@param jsonObj a Map-of-Map representation of the JSON input stream.
Traverse the JsonObject associated to an array ( of any type ) . Convert and assign the list of items in the JsonObject ( stored in the @items field ) to each array element . All array elements are processed excluding elements that reference an unresolved object . These are filled in later .