src/main/java/com/cedarsoftware/util/io/JsonWriter.java
public void writeImpl(Object obj, boolean showType, boolean allowRef, boolean allowCustom) throws IOException
    {
        if (neverShowType)
        {
            showType = false;
        }
        if (obj == null)
        {
            out.write("null");
            return;
        }

        if (allowCustom && writeIfMatching(obj, showType, out))
        {
            return;
        }

        if (allowRef && writeOptionalReference(obj))
        {
            return;
        }

        if (obj.getClass().isArray())
        {
            writeArray(obj, showType);
        }
        else if (obj instanceof Collection)
        {
            writeCollection((Collection) obj, showType);
        }
        else if (obj instanceof JsonObject)
        {   // symmetric support for writing Map of Maps representation back as equivalent JSON format.
            JsonObject jObj = (JsonObject) obj;
            if (jObj.isArray())
            {
                writeJsonObjectArray(jObj, showType);
            }
            else if (jObj.isCollection())
            {
                writeJsonObjectCollection(jObj, showType);
            }
            else if (jObj.isMap())
            {
                if (!writeJsonObjectMapWithStringKeys(jObj, showType))
                {
                    writeJsonObjectMap(jObj, showType);
                }
            }
            else
            {
                writeJsonObjectObject(jObj, showType);
            }
        }
        else if (obj instanceof Map)
        {
            if (!writeMapWithStringKeys((Map) obj, showType))
            {
                writeMap((Map) obj, showType);
            }
        }
        else
        {
            writeObject(obj, showType, false);
        }
    }
public void writeImpl(Object obj, boolean showType, boolean allowRef, boolean allowCustom) throws IOException
    {
        if (neverShowType)
        {
            showType = false;
        }
        if (obj == null)
        {
            out.write("null");
            return;
        }

        if (allowCustom && writeIfMatching(obj, showType, out))
        {
            return;
        }

        if (allowRef && writeOptionalReference(obj))
        {
            return;
        }

        if (obj.getClass().isArray())
        {
            writeArray(obj, showType);
        }
        else if (obj instanceof Collection)
        {
            writeCollection((Collection) obj, showType);
        }
        else if (obj instanceof JsonObject)
        {   // symmetric support for writing Map of Maps representation back as equivalent JSON format.
            JsonObject jObj = (JsonObject) obj;
            if (jObj.isArray())
            {
                writeJsonObjectArray(jObj, showType);
            }
            else if (jObj.isCollection())
            {
                writeJsonObjectCollection(jObj, showType);
            }
            else if (jObj.isMap())
            {
                if (!writeJsonObjectMapWithStringKeys(jObj, showType))
                {
                    writeJsonObjectMap(jObj, showType);
                }
            }
            else
            {
                writeJsonObjectObject(jObj, showType);
            }
        }
        else if (obj instanceof Map)
        {
            if (!writeMapWithStringKeys((Map) obj, showType))
            {
                writeMap((Map) obj, showType);
            }
        }
        else
        {
            writeObject(obj, showType, false);
        }
    }
public void writeImpl ( Object obj , boolean showType , boolean allowRef , boolean allowCustom ) throws IOException { if ( neverShowType ) { showType = false ; } if ( obj == null ) { out . write ( "null" ) ; return ; } if ( allowCustom && writeIfMatching ( obj , showType , out ) ) { return ; } if ( allowRef && writeOptionalReference ( obj ) ) { return ; } if ( obj . getClass ( ) . isArray ( ) ) { writeArray ( obj , showType ) ; } else if ( obj instanceof Collection ) { writeCollection ( ( Collection ) obj , showType ) ; } else if ( obj instanceof JsonObject ) { // symmetric support for writing Map of Maps representation back as equivalent JSON format. JsonObject jObj = ( JsonObject ) obj ; if ( jObj . isArray ( ) ) { writeJsonObjectArray ( jObj , showType ) ; } else if ( jObj . isCollection ( ) ) { writeJsonObjectCollection ( jObj , showType ) ; } else if ( jObj . isMap ( ) ) { if ( ! writeJsonObjectMapWithStringKeys ( jObj , showType ) ) { writeJsonObjectMap ( jObj , showType ) ; } } else { writeJsonObjectObject ( jObj , showType ) ; } } else if ( obj instanceof Map ) { if ( ! writeMapWithStringKeys ( ( Map ) obj , showType ) ) { writeMap ( ( Map ) obj , showType ) ; } } else { writeObject ( obj , showType , false ) ; } }
Main entry point (mostly used internally, but may be called from a Custom JSON writer).
This method will write out whatever object type it is given, including JsonObject's.
It will handle null, detecting if a custom writer should be called, array, array of
JsonObject, Map, Map of JsonObjects, Collection, Collection of JsonObject, any regular
object, or a JsonObject representing a regular object.
@param obj Object to be written
@param showType if set to true, the @type tag will be output.  If false, it will be
@param allowRef if set to true, @ref will be used, otherwise 2+ occurrence will be
output as full object.
@param allowCustom if set to true, the object being called will allowed to be checked for a matching
custom writer to be used. This does not affect subobjects, just the top-level 'obj'
being passed in.
@throws IOException if one occurs on the underlying output stream.
Main entry point ( mostly used internally but may be called from a Custom JSON writer ) . This method will write out whatever object type it is given including JsonObject s . It will handle null detecting if a custom writer should be called array array of JsonObject Map Map of JsonObjects Collection Collection of JsonObject any regular object or a JsonObject representing a regular object .