This is an automated email from the ASF dual-hosted git repository. mattisonchao pushed a commit to branch fixes.json-schema-compatible-avro-name-validator in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 5f6f5901cf471187c51f04545bb577b05d1e8130 Author: mattisonchao <[email protected]> AuthorDate: Wed Feb 25 01:58:37 2026 +0800 [fix][broker] Use compatible Avro name validator in JsonSchemaCompatibilityCheck Apply the same COMPATIBLE_NAME_VALIDATOR to JsonSchemaCompatibilityCheck's isAvroSchema() method to allow '$' in schema record names, matching the fix already applied to AvroSchemaBasedCompatibilityCheck, SchemaRegistryServiceImpl, and StructSchemaDataValidator in #25193. Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../service/schema/JsonSchemaCompatibilityCheck.java | 3 ++- .../schema/JsonSchemaCompatibilityCheckTest.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheck.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheck.java index cbdca3c4732..94afdd14620 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheck.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheck.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.module.jsonSchema.JsonSchema; import java.io.IOException; import org.apache.avro.Schema; import org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException; +import org.apache.pulsar.broker.service.schema.validator.StructSchemaDataValidator; import org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy; import org.apache.pulsar.common.protocol.schema.SchemaData; import org.apache.pulsar.common.schema.SchemaType; @@ -91,7 +92,7 @@ public class JsonSchemaCompatibilityCheck extends AvroSchemaBasedCompatibilityCh private boolean isAvroSchema(SchemaData schemaData) { try { - Schema.Parser fromParser = new Schema.Parser(); + Schema.Parser fromParser = new Schema.Parser(StructSchemaDataValidator.COMPATIBLE_NAME_VALIDATOR); fromParser.setValidateDefaults(false); Schema fromSchema = fromParser.parse(new String(schemaData.getData(), UTF_8)); return true; diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheckTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheckTest.java index b68ecb08799..85e5894240c 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheckTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/JsonSchemaCompatibilityCheckTest.java @@ -18,6 +18,7 @@ */ package org.apache.pulsar.broker.service.schema; +import static java.nio.charset.StandardCharsets.UTF_8; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; @@ -60,6 +61,23 @@ public class JsonSchemaCompatibilityCheckTest extends BaseAvroSchemaCompatibilit Assert.assertTrue(jsonSchemaCompatibilityCheck.isCompatible(from, to, SchemaCompatibilityStrategy.FULL)); } + @Test + public void testIsAvroSchemaWithDollarSignInRecordName() { + String schemaWithDollar = + "{\"type\":\"record\",\"name\":\"Outer$Inner\",\"namespace\":\"org.example\"," + + "\"fields\":[{\"name\":\"field1\",\"type\":\"string\"}]}"; + SchemaData avroData = SchemaData.builder() + .data(schemaWithDollar.getBytes(UTF_8)) + .type(SchemaType.JSON) + .build(); + SchemaData avroData2 = SchemaData.builder() + .data(schemaWithDollar.getBytes(UTF_8)) + .type(SchemaType.JSON) + .build(); + JsonSchemaCompatibilityCheck check = new JsonSchemaCompatibilityCheck(); + Assert.assertTrue(check.isCompatible(avroData, avroData2, SchemaCompatibilityStrategy.FULL)); + } + @Data private static class Foo { private String field1;
