static void jsonValToJSONString ( final Object jsonVal , final Map < ReferenceEqualityKey < JSONReference > , CharSequence > jsonReferenceToId , final boolean includeNullValuedFields , final int depth , final int indentWidth , final StringBuilder buf ) { if ( jsonVal == null ) { buf . append ( "null" ) ; } else if ( jsonVal instanceof JSONObject ) { // Serialize JSONObject to string ( ( JSONObject ) jsonVal ) . toJSONString ( jsonReferenceToId , includeNullValuedFields , depth , indentWidth , buf ) ; } else if ( jsonVal instanceof JSONArray ) { // Serialize JSONArray to string ( ( JSONArray ) jsonVal ) . toJSONString ( jsonReferenceToId , includeNullValuedFields , depth , indentWidth , buf ) ; } else if ( jsonVal instanceof JSONReference ) { // Serialize JSONReference to string final Object referencedObjectId = jsonReferenceToId . get ( new ReferenceEqualityKey <> ( ( JSONReference ) jsonVal ) ) ; jsonValToJSONString ( referencedObjectId , jsonReferenceToId , includeNullValuedFields , depth , indentWidth , buf ) ; } else if ( jsonVal instanceof CharSequence || jsonVal instanceof Character || jsonVal . getClass ( ) . isEnum ( ) ) { // Serialize String, Character or enum val to quoted/escaped string buf . append ( ' ' ) ; JSONUtils . escapeJSONString ( jsonVal . toString ( ) , buf ) ; buf . append ( ' ' ) ; } else { // Serialize a numeric or Boolean type (Integer, Long, Short, Float, Double, Boolean, Byte) to string // (doesn't need quoting or escaping) buf . append ( jsonVal . toString ( ) ) ; } }
Serialize a JSON object array or value .