public final void serialize()

in serialization/src/main/java/com/twitter/serial/serializer/ValueSerializer.java [37:51]


    public final void serialize(@NotNull SerializationContext context,
            @NotNull SerializerOutput output, @Nullable T object) throws IOException {
        if (!SerializationUtils.writeNullIndicator(output, object)) {
            final ByteBufferSerializerOutput byteBufferOutput =
                    output instanceof ByteBufferSerializerOutput ? (ByteBufferSerializerOutput) output : null;
            final int position = byteBufferOutput != null ? byteBufferOutput.getPosition() : 0;

            serializeValue(context, output, object);

            // Check that the value does not start with a null, since it would be ambiguous with a null value.
            if (byteBufferOutput != null && byteBufferOutput.peekTypeAtPosition(position) == SerializerDefs.TYPE_NULL) {
                throw new IllegalStateException("Values with null in the first field are ambiguous.");
            }
        }
    }