Claus Ibsen created CAMEL-27175:
-----------------------------------

             Summary: camel-kafka - schemaRegistryVendor apicurio with 
schemaFormat json fails: json-schema-validator 3.x conflicts with the Apicurio 
serde
                 Key: CAMEL-27175
                 URL: https://issues.apache.org/jira/browse/CAMEL-27175
             Project: Camel
          Issue Type: Bug
          Components: camel-jbang, camel-kafka
            Reporter: Claus Ibsen


With {{schemaRegistryVendor=apicurio}} and {{schemaFormat=json}} (CAMEL-27130), 
sending to Kafka fails on Camel JBang 4.24.0-SNAPSHOT:

{noformat}
java.lang.IncompatibleClassChangeError: class 
com.networknt.schema.resource.DefaultSchemaLoader can not implement
com.networknt.schema.resource.SchemaLoader, because it is not an interface
(com.networknt.schema.resource.SchemaLoader is in unnamed module of loader 
'app')
{noformat}

h3. Cause

The Apicurio JSON Schema serde 
({{io.apicurio:apicurio-registry-jsonschema-serde-kafka}}) is built against 
{{com.networknt:json-schema-validator}} 1.5.x. That is true of the 3.3.3 that 
Camel JBang downloads, and also of 3.3.4, the newest Apicurio release (its pom 
has {{json-schema-validator.version}} 1.5.9).

Camel moved json-schema-validator to 3.0.9 for Jackson 3 (CAMEL-23172). Camel 
JBang has it on the application classpath, through camel-jbang-core and the 
YAML DSL validator. Both versions use the package {{com.networknt.schema}}, and 
in 3.x {{SchemaLoader}} is a class instead of an interface. So the 1.5.x 
classes the serde brings fail to link against the 3.0.9 ones that are already 
loaded.

The same conflict can happen in any application that has the Apicurio JSON 
Schema serde together with a Camel module using json-schema-validator 3.x: 
camel-json-validator, camel-yaml-dsl-validator, camel-openai or 
camel-mcp-server.

h3. Reproduce

Run Apicurio Registry 3.x and Kafka, register a JSON Schema for the subject 
{{orders-value}} (without one the serializer fails earlier with a "not found" 
ProblemDetails), then run with {{camel run route.yaml}}:

{code:yaml}
- route:
    from:
      uri: timer:t?repeatCount=1
      steps:
        - setBody:
            constant: '{"id": 1, "item": "camel"}'
        - unmarshal:
            json: {}
        - to:
            uri: kafka:orders
            parameters:
              brokers: localhost:9092
              schemaRegistryVendor: apicurio
              schemaRegistryURL: http://localhost:8080/apis/registry/v3
              schemaFormat: json
{code}

{{schemaFormat=avro}} with {{apicurio}} works. {{json}} with {{confluent}} 
works too, because the Confluent serde does not use networknt.

h3. What is needed

{{apicurio}} with {{json}} should work in Camel JBang and in Camel 
applications, also next to the Camel modules that use json-schema-validator 
3.x. Possible ways:
* Camel JBang keeps its own json-schema-validator (used for YAML validation) 
away from the application classpath, for example by shading it in 
camel-jbang-core.
* An Apicurio release built on json-schema-validator 2.x/3.x: Camel would then 
use that version and say so in the docs.
* Until then, the camel-kafka docs and the error message for {{apicurio}} with 
{{json}} point out the conflict.

Found while adding the schema registry options to the Kafka Kamelets 
(apache/camel-kamelets#3203, which now documents that {{apicurio}} needs 
{{avro}}).




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to