@SuppressWarnings("unchecked")
    static void writeObjectTo(Output output, Object value,
            Schema<?> currentSchema, IdStrategy strategy) throws IOException
    {
        if (Collections.class == value.getClass().getDeclaringClass())
        {
            writeNonPublicCollectionTo(output, value, currentSchema, strategy);
            return;
        }

        if (EnumSet.class.isAssignableFrom(value.getClass()))
        {
            strategy.writeEnumIdTo(output, ID_ENUM_SET,
                    EnumIO.getElementTypeFromEnumSet(value));

            // TODO optimize
        }
        else
        {
            strategy.writeCollectionIdTo(output, ID_COLLECTION,
                    value.getClass());
        }

        if (output instanceof StatefulOutput)
        {
            // update using the derived schema.
            ((StatefulOutput) output).updateLast(strategy.COLLECTION_SCHEMA,
                    currentSchema);
        }

        strategy.COLLECTION_SCHEMA.writeTo(output, (Collection<Object>) value);
    }
Used when the type is an interface (Collection/List/Set/SortedSet).

@author David Yu
@created Apr 24, 2012
protostuff-runtime/src/main/java/io/protostuff/runtime/PolymorphicCollectionSchema.java