Previously, I used SchemaLoader
to load json schema files I had locally and validated JSON objects against them. Some of my schemas have refs to other local files.
I'm now migrating to the confluent schema registry and I've registered my schemas in the registry. Using io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient
, I am able to query for the latest schema metadata for a particular subject and get the schema iteslf, references, etc.
However, it's unclear to me how to use org.everit.json.schema.loader.SchemaLoader
(or anything else that can validate messages) to load the schema text and have a schema ready. When I run this code, the last line gets an exception becuase it doesn't understand the #ref
in the top level schema. The schema that comes from the registry has the references
populated, but I'm not sure how to plug them in to the SchemaLoader.
java.net.MalformedURLException: no protocol: RefSchema1.schema.json
CachedSchemaRegistryClient registryClient = new CachedSchemaRegistryClient(schemaRegistryUrl, 10);
System.out.println("Schema mode: " + registryClient.getMode());
var schemaMetaData = registryClient.getLatestSchemaMetadata(SCHEMA_SUBJECT);
System.out.println("analysis output schema ID: " + schemaMetaData.getId());
System.out.println("analysis output schema Version: " + schemaMetaData.getVersion());
System.out.println("analysis output schema: " + schemaMetaData.getSchema());
System.out.println("analysis output schema type: " + schemaMetaData.getSchemaType());
System.out.println("analysis output schema refs: " + schemaMetaData.getReferences());
var schemaObj = new JSONObject(schemaMetaData.getSchema());
Schema schema = SchemaLoader.load(schemaObj);
Another odd thing happenign is taht when I call registryClient.getSchemaById() using the id from the schema meata data, I get an "Invalid schema" exception for the schema.