@Override
    public WritableTypeId writeTypePrefix(final JsonGenerator jsonGenerator, final WritableTypeId writableTypeId) throws IOException {
        if (writableTypeId.valueShape == JsonToken.START_OBJECT) {
            if (writableTypeId.forValue instanceof Map) {
                writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
                jsonGenerator.writeStartArray();
            } else {
                jsonGenerator.writeStartObject();
            }
        } else if (writableTypeId.valueShape == JsonToken.START_ARRAY) {
            if (writableTypeId.forValue instanceof List || writableTypeId.forValue instanceof Set) {
                writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
                jsonGenerator.writeStartArray();
            } else {
                jsonGenerator.writeStartArray();
            }
        } else if (canWriteTypeId()) {
            writeTypePrefix(jsonGenerator, getTypeIdResolver().idFromValueAndType(writableTypeId.forValue, getClassFromObject(writableTypeId.forValue)));
        } else {
            throw new IllegalStateException("Could not write prefix: shape[" + writableTypeId.valueShape + "] value[" + writableTypeId.forValue + "]");
        }

        return writableTypeId;
    }
GraphSON 2.0 {@code TypeSerializer}.

@author Kevin Gallardo (https://kgdo.me)
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializerV3.java