io.apicurio.registry.serde.SchemaResolverConfigurer Maven / Gradle / Ivy
package io.apicurio.registry.serde;
import io.apicurio.registry.resolver.DefaultSchemaResolver;
import io.apicurio.registry.resolver.SchemaParser;
import io.apicurio.registry.resolver.SchemaResolver;
import io.apicurio.registry.resolver.SchemaResolverConfig;
import io.apicurio.registry.resolver.utils.Utils;
import io.apicurio.registry.rest.client.RegistryClient;
import java.util.Map;
import java.util.Objects;
/**
* Base class for any kind of serializer/deserializer that depends on {@link SchemaResolver}
*/
public class SchemaResolverConfigurer {
protected SchemaResolver schemaResolver;
/**
* Constructor.
*/
public SchemaResolverConfigurer() {
super();
}
public SchemaResolverConfigurer(RegistryClient client) {
this(client, new DefaultSchemaResolver<>());
}
public SchemaResolverConfigurer(SchemaResolver schemaResolver) {
this(null, schemaResolver);
}
public SchemaResolverConfigurer(RegistryClient client, SchemaResolver schemaResolver) {
this();
setSchemaResolver(schemaResolver);
getSchemaResolver().setClient(client);
}
public SchemaResolver getSchemaResolver() {
return schemaResolver;
}
public void setSchemaResolver(SchemaResolver schemaResolver) {
this.schemaResolver = Objects.requireNonNull(schemaResolver);
}
protected void configure(Map configs, boolean isKey, SchemaParser schemaParser) {
Objects.requireNonNull(configs);
Objects.requireNonNull(schemaParser);
if (this.schemaResolver == null) {
Object sr = configs.get(SerdeConfig.SCHEMA_RESOLVER);
if (null == sr) {
this.setSchemaResolver(new DefaultSchemaResolver<>());
} else {
Utils.instantiate(SchemaResolver.class, sr, this::setSchemaResolver);
}
}
// enforce default artifactResolverStrategy for kafka apps
if (!configs.containsKey(SchemaResolverConfig.ARTIFACT_RESOLVER_STRATEGY)) {
configs.put(SchemaResolverConfig.ARTIFACT_RESOLVER_STRATEGY,
SerdeConfig.ARTIFACT_RESOLVER_STRATEGY_DEFAULT);
}
// isKey is passed via config property
configs.put(SerdeConfig.IS_KEY, isKey);
getSchemaResolver().configure(configs, schemaParser);
}
}