private void writeJsonObjectObject(JsonObject jObj, boolean showType) throws IOException
    {
        if (neverShowType)
        {
            showType = false;
        }
        final Writer output = this.out;
        boolean referenced = objsReferenced.containsKey(jObj) && jObj.hasId();
        showType = showType && jObj.type != null;
        Class type = null;

        output.write('{');
        tabIn();
        if (referenced)
        {
            writeId(String.valueOf(jObj.id));
        }

        if (showType)
        {
            if (referenced)
            {
                output.write(',');
                newLine();
            }
            output.write(shortMetaKeys ? "\"@t\":\"" : "\"@type\":\"");
            output.write(getSubstituteTypeName(jObj.type));
            output.write('"');
            try  { type = MetaUtils.classForName(jObj.type, getClassLoader()); } catch(Exception ignored) { type = null; }
        }

        if (jObj.isEmpty())
        {
            tabOut();
            output.write('}');
            return;
        }

        if (showType || referenced)
        {
            output.write(',');
            newLine();
        }

        Iterator<Map.Entry<String,Object>> i = jObj.entrySet().iterator();
        boolean first = true;

        while (i.hasNext())
        {
            Map.Entry<String, Object>entry = i.next();
            if (skipNullFields && entry.getValue() == null)
            {
                continue;
            }

            if (!first)
            {
                output.write(',');
                newLine();
            }
            first = false;
            final String fieldName = entry.getKey();
            output.write('"');
            output.write(fieldName);
            output.write("\":");
            Object value = entry.getValue();

            if (value == null)
            {
                output.write("null");
            }
            else if (neverShowType && MetaUtils.isPrimitive(value.getClass()))
            {
                writePrimitive(value, false);
            }
            else if (value instanceof BigDecimal || value instanceof BigInteger)
            {
                writeImpl(value, !doesValueTypeMatchFieldType(type, fieldName, value));
            }
            else if (value instanceof Number || value instanceof Boolean)
            {
                output.write(value.toString());
            }
            else if (value instanceof String)
            {
                writeJsonUtf8String((String) value, output);
            }
            else if (value instanceof Character)
            {
                writeJsonUtf8String(String.valueOf(value), output);
            }
            else
            {
                writeImpl(value, !doesValueTypeMatchFieldType(type, fieldName, value));
            }
        }
        tabOut();
        output.write('}');
    }
private void writeJsonObjectObject(JsonObject jObj, boolean showType) throws IOException
    {
        if (neverShowType)
        {
            showType = false;
        }
        final Writer output = this.out;
        boolean referenced = objsReferenced.containsKey(jObj) && jObj.hasId();
        showType = showType && jObj.type != null;
        Class type = null;

        output.write('{');
        tabIn();
        if (referenced)
        {
            writeId(String.valueOf(jObj.id));
        }

        if (showType)
        {
            if (referenced)
            {
                output.write(',');
                newLine();
            }
            output.write(shortMetaKeys ? "\"@t\":\"" : "\"@type\":\"");
            output.write(getSubstituteTypeName(jObj.type));
            output.write('"');
            try  { type = MetaUtils.classForName(jObj.type, getClassLoader()); } catch(Exception ignored) { type = null; }
        }

        if (jObj.isEmpty())
        {
            tabOut();
            output.write('}');
            return;
        }

        if (showType || referenced)
        {
            output.write(',');
            newLine();
        }

        Iterator<Map.Entry<String,Object>> i = jObj.entrySet().iterator();
        boolean first = true;

        while (i.hasNext())
        {
            Map.Entry<String, Object>entry = i.next();
            if (skipNullFields && entry.getValue() == null)
            {
                continue;
            }

            if (!first)
            {
                output.write(',');
                newLine();
            }
            first = false;
            final String fieldName = entry.getKey();
            output.write('"');
            output.write(fieldName);
            output.write("\":");
            Object value = entry.getValue();

            if (value == null)
            {
                output.write("null");
            }
            else if (neverShowType && MetaUtils.isPrimitive(value.getClass()))
            {
                writePrimitive(value, false);
            }
            else if (value instanceof BigDecimal || value instanceof BigInteger)
            {
                writeImpl(value, !doesValueTypeMatchFieldType(type, fieldName, value));
            }
            else if (value instanceof Number || value instanceof Boolean)
            {
                output.write(value.toString());
            }
            else if (value instanceof String)
            {
                writeJsonUtf8String((String) value, output);
            }
            else if (value instanceof Character)
            {
                writeJsonUtf8String(String.valueOf(value), output);
            }
            else
            {
                writeImpl(value, !doesValueTypeMatchFieldType(type, fieldName, value));
            }
        }
        tabOut();
        output.write('}');
    }
private void writeJsonObjectObject ( JsonObject jObj , boolean showType ) throws IOException { if ( neverShowType ) { showType = false ; } final Writer output = this . out ; boolean referenced = objsReferenced . containsKey ( jObj ) && jObj . hasId ( ) ; showType = showType && jObj . type != null ; Class type = null ; output . write ( ' ' ) ; tabIn ( ) ; if ( referenced ) { writeId ( String . valueOf ( jObj . id ) ) ; } if ( showType ) { if ( referenced ) { output . write ( ' ' ) ; newLine ( ) ; } output . write ( shortMetaKeys ? "\"@t\":\"" : "\"@type\":\"" ) ; output . write ( getSubstituteTypeName ( jObj . type ) ) ; output . write ( ' ' ) ; try { type = MetaUtils . classForName ( jObj . type , getClassLoader ( ) ) ; } catch ( Exception ignored ) { type = null ; } } if ( jObj . isEmpty ( ) ) { tabOut ( ) ; output . write ( ' ' ) ; return ; } if ( showType || referenced ) { output . write ( ' ' ) ; newLine ( ) ; } Iterator < Map . Entry < String , Object > > i = jObj . entrySet ( ) . iterator ( ) ; boolean first = true ; while ( i . hasNext ( ) ) { Map . Entry < String , Object > entry = i . next ( ) ; if ( skipNullFields && entry . getValue ( ) == null ) { continue ; } if ( ! first ) { output . write ( ' ' ) ; newLine ( ) ; } first = false ; final String fieldName = entry . getKey ( ) ; output . write ( ' ' ) ; output . write ( fieldName ) ; output . write ( "\":" ) ; Object value = entry . getValue ( ) ; if ( value == null ) { output . write ( "null" ) ; } else if ( neverShowType && MetaUtils . isPrimitive ( value . getClass ( ) ) ) { writePrimitive ( value , false ) ; } else if ( value instanceof BigDecimal || value instanceof BigInteger ) { writeImpl ( value , ! doesValueTypeMatchFieldType ( type , fieldName , value ) ) ; } else if ( value instanceof Number || value instanceof Boolean ) { output . write ( value . toString ( ) ) ; } else if ( value instanceof String ) { writeJsonUtf8String ( ( String ) value , output ) ; } else if ( value instanceof Character ) { writeJsonUtf8String ( String . valueOf ( value ) , output ) ; } else { writeImpl ( value , ! doesValueTypeMatchFieldType ( type , fieldName , value ) ) ; } } tabOut ( ) ; output . write ( ' ' ) ; }
Write fields of an Object (JsonObject)
Write fields of an Object ( JsonObject )