public void writeObject()

in core/src/main/java/flex/messaging/io/amf/Amf3Output.java [99:185]


    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();
            writeAMFString(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...
                writeAMFString(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) {
            writeAMFDate((Date) o);
        } else if (o instanceof Calendar) {
            writeAMFDate(((Calendar) o).getTime());
        } else if (o instanceof Document) {
            if (context.legacyXMLDocument)
                out.write(kXMLType); // Legacy flash.xml.XMLDocument Type
            else
                out.write(kAvmPlusXmlType); // New E4X XML Type
            if (!byReference(o)) {
                String xml = documentToString(o);
                if (isDebug)
                    trace.write(xml);

                writeAMFUTF(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;
            writeAMFString(enumValue.name());
        } else {
            // We have an Object or Array type...
            Class cls = o.getClass();

            if (context.legacyMap && o instanceof Map && !(o instanceof ASObject)) {
                writeMapAsECMAArray((Map) o);
            } else if (!context.legacyDictionary && o instanceof Dictionary) {
                writeDictionary((Dictionary) o);
            } else if (o instanceof Collection) {
                if (o instanceof List && context.preferVectors)
                    writeListAsTypedVector((List) o);
                else if (context.legacyCollection)
                    writeCollection((Collection) o, null);
                else
                    writeArrayCollection((Collection) o, null);
            } else if (cls.isArray()) {
                Class<?> componentType = cls.getComponentType();
                // Convert to vector if requested, except for character and byte arrays
                if (context.preferVectors &&
                        !(componentType.equals(Byte.class) || componentType.equals(byte.class)) &&
                        !(componentType.equals(Character.class) || componentType.equals(char.class)))
                    writeArrayAsTypedVector(o, componentType);
                else
                    writeAMFArray(o, componentType);
            } else {
                //Special Case: wrap RowSet in PageableRowSet for Serialization
                if (o instanceof RowSet) {
                    o = new PagedRowSet((RowSet) o, Integer.MAX_VALUE, false);
                } else if (context.legacyThrowable && o instanceof Throwable) {
                    o = new StatusInfoProxy((Throwable) o);
                }

                writeCustomObject(o);
            }
        }
    }