static boolean tryWriteWithoutCause(Output output, Object value,
            Schema<Object> schema) throws IOException
    {
        if (schema instanceof RuntimeSchema)
        {
            // ignore the field "cause" if its references itself (cyclic)
            final RuntimeSchema<Object> ms = (RuntimeSchema<Object>) schema;
            if (ms.getFieldCount() > 1 && ms.getFields().get(1).name.equals("cause"))
            {
                final Object cause;
                try
                {
                    cause = (__cause != null) ? __cause.get(value) : null;
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }

                if (cause == null || cause == value)
                {
                    // its cyclic, skip the second field "cause"
                    ms.getFields().get(0).writeTo(output, value);

                    for (int i = 2, len = ms.getFieldCount(); i < len; i++)
                        ms.getFields().get(i).writeTo(output, value);

                    return true;
                }
            }
        }

        return false;
    }
Used when the type is assignable from {@link java.lang.Throwable}.

@author David Yu
@created May 2, 2012
protostuff-runtime/src/main/java/io/protostuff/runtime/PolymorphicThrowableSchema.java