use of io.confluent.kafka.schemaregistry.storage.SchemaRegistryKey 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;
}
Aggregations