public void writeObject()

in core/src/main/java/flex/messaging/io/amfx/AmfxOutput.java [104:183]


    public void writeObject(Object o) throws IOException {
        if (o == null) {
            writeAMFNull();
            return;
        }

        if (!context.legacyExternalizable && o instanceof Externalizable) {
            writeCustomObject(o);
        } else if (o instanceof String || o instanceof Character) {
            String s = o.toString();
            writeString(s);
        } else if (o instanceof Number) {
            if (o instanceof Integer || o instanceof Short || o instanceof Byte) {
                int i = ((Number) o).intValue();
                writeAMFInt(i);
            } else if (!context.legacyBigNumbers &&
                    (o instanceof BigInteger || o instanceof BigDecimal)) {
                // Using double to write big numbers such as BigInteger or
                // BigDecimal can result in information loss so we write
                // them as String by default...
                writeString(o.toString());
            } else {
                double d = ((Number) o).doubleValue();
                writeAMFDouble(d);
            }
        } else if (o instanceof Boolean) {
            writeAMFBoolean(((Boolean) o).booleanValue());
        }
        // We have a complex type...
        else if (o instanceof Date) {
            writeDate((Date) o);
        } else if (o instanceof Calendar) {
            writeDate(((Calendar) o).getTime());
        } else if (o instanceof Document) {
            String xml = documentToString(o);

            int len = xml.length() + 15; // <xml>...</xml>

            StringBuffer sb = new StringBuffer(len);
            sb.append(XML_OPEN_TAG);
            writeEscapedString(sb, xml);
            sb.append(XML_CLOSE_TAG);

            writeUTF(sb);

            if (isDebug)
                trace.writeString(xml);
        }
        // If there is a proxy for this,write it as a custom object so the default
        // behavior can be overriden.
        else if (o instanceof Enum && PropertyProxyRegistry.getRegistry().getProxy(o.getClass()) == null) {
            Enum<?> enumValue = (Enum<?>) o;
            writeString(enumValue.name());
        } else {
            //We have an Object or Array type...
            Class cls = o.getClass();

            if (o instanceof Map && context.legacyMap && !(o instanceof ASObject)) {
                writeMapAsECMAArray((Map) o);
            } else if (!context.legacyDictionary && o instanceof Dictionary) {
                writeDictionary((Dictionary) o);
            } else if (o instanceof Collection) {
                if (context.legacyCollection)
                    writeCollection((Collection) o, null);
                else
                    writeArrayCollection((Collection) o, null);
            } else if (cls.isArray()) {
                writeAMFArray(o, cls.getComponentType());
            } else {
                //Special Case: wrap RowSet in PageableRowSet for Serialization
                if (o instanceof RowSet) {
                    o = new PagedRowSet((RowSet) o, Integer.MAX_VALUE, false);
                } else if (o instanceof Throwable && context.legacyThrowable) {
                    o = new StatusInfoProxy((Throwable) o);
                }

                writeCustomObject(o);
            }
        }
    }