Search in sources :

Example 1 with SchemaRegistryKeyType

use of io.confluent.kafka.schemaregistry.storage.SchemaRegistryKeyType in project schema-registry by confluentinc.

the class SchemaRegistrySerializer method deserializeKey.

@Override
public SchemaRegistryKey deserializeKey(byte[] key) throws SerializationException {
    SchemaRegistryKey schemaKey = null;
    SchemaRegistryKeyType keyType = null;
    try {
        try {
            Map<Object, Object> keyObj = null;
            keyObj = JacksonMapper.INSTANCE.readValue(key, new TypeReference<Map<Object, Object>>() {
            });
            keyType = SchemaRegistryKeyType.forName((String) keyObj.get("keytype"));
            if (keyType == SchemaRegistryKeyType.CONFIG) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, ConfigKey.class);
            } else if (keyType == SchemaRegistryKeyType.MODE) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, ModeKey.class);
            } else if (keyType == SchemaRegistryKeyType.NOOP) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, NoopKey.class);
            } else if (keyType == SchemaRegistryKeyType.CONTEXT) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, ContextKey.class);
            } else if (keyType == SchemaRegistryKeyType.DELETE_SUBJECT) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, DeleteSubjectKey.class);
            } else if (keyType == SchemaRegistryKeyType.CLEAR_SUBJECT) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, ClearSubjectKey.class);
            } else if (keyType == SchemaRegistryKeyType.SCHEMA) {
                schemaKey = JacksonMapper.INSTANCE.readValue(key, SchemaKey.class);
                validateMagicByte((SchemaKey) schemaKey);
            }
        } catch (JsonProcessingException e) {
            String type = "unknown";
            if (keyType != null) {
                type = keyType.name();
            }
            throw new SerializationException("Failed to deserialize " + type + " key", e);
        }
    } catch (IOException e) {
        throw new SerializationException("Error while deserializing schema key", e);
    }
    return schemaKey;
}
Also used : ConfigKey(io.confluent.kafka.schemaregistry.storage.ConfigKey) SerializationException(io.confluent.kafka.schemaregistry.storage.exceptions.SerializationException) SchemaRegistryKeyType(io.confluent.kafka.schemaregistry.storage.SchemaRegistryKeyType) IOException(java.io.IOException) SchemaKey(io.confluent.kafka.schemaregistry.storage.SchemaKey) DeleteSubjectKey(io.confluent.kafka.schemaregistry.storage.DeleteSubjectKey) SchemaRegistryKey(io.confluent.kafka.schemaregistry.storage.SchemaRegistryKey) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NoopKey(io.confluent.kafka.schemaregistry.storage.NoopKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ConfigKey (io.confluent.kafka.schemaregistry.storage.ConfigKey)1 DeleteSubjectKey (io.confluent.kafka.schemaregistry.storage.DeleteSubjectKey)1 NoopKey (io.confluent.kafka.schemaregistry.storage.NoopKey)1 SchemaKey (io.confluent.kafka.schemaregistry.storage.SchemaKey)1 SchemaRegistryKey (io.confluent.kafka.schemaregistry.storage.SchemaRegistryKey)1 SchemaRegistryKeyType (io.confluent.kafka.schemaregistry.storage.SchemaRegistryKeyType)1 SerializationException (io.confluent.kafka.schemaregistry.storage.exceptions.SerializationException)1 IOException (java.io.IOException)1