apache / apache/pulsar

[Bug] [schema] Not a JSON Object: "string"

Open
#21,241 1 comment 0 reactions 0 assignees View on GitHub
Stale type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Version

all

### Minimal reproduce step

1、create producer1 by schema [Schema.JSON(String.class)]
`Producer producer = client.newProducer(Schema.JSON(String.class))
.topic("test-tenant/test-ns/test-topic").enableBatching(false).create();`
and send a message

2、create producer2 by schema [Schema.AUTO_PRODUCE_BYTES()]
`Producer producer = client.newProducer(Schema.AUTO_PRODUCE_BYTES())
.topic("test-tenant/test-ns/test-topic").enableBatching(false).create();`
we will encounter an error:
![image](https://github.com/apache/pulsar/assets/16524922/738835d2-c2dc-4401-ab92-dc1b29343251)

3、execute schemas admin: sh bin/pulsar-admin schemas get test-tenant/test-ns/test-topic
We will see the following error:
![image](https://github.com/apache/pulsar/assets/16524922/49b4a252-f9f0-4c52-96a1-c3e8615898dd)

### What did you expect to see?
Create producer use Schema.AUTO_PRODUCE_BYTES() will success and admin schema get return a result.

### What did you see instead?

Throw exception: java.lang.IllegalStateException: Not a JSON Object: "string"

### Anything else?

1、There is no problem if the user send string type message uses Schema.STRING instead of Schema.JSON(String.class). The Schema.JSON(String.class) unable to reverse parse.

2、This will also cause problems when use geo-replication if the remote topics has a incorrect schema:
The incorrect schema:
{
"name" : "test-topic",
"schema" : "InN0cmluZyI=",
"type" : "JSON",
"properties" : {
"__jsr310ConversionEnabled" : "false",
"__alwaysAllowNull" : "true"
},
"schemaDefinition" : "\"string\""
}

The current logic is create geo producer:
`this.producerBuilder = replicationClient.newProducer(Schema.AUTO_PRODUCE_BYTES()) //
.topic(remoteTopicName)
.messageRoutingMode(MessageRoutingMode.SinglePartition)
.enableBatching(false)
.sendTimeout(0, TimeUnit.SECONDS) //
.maxPendingMessages(producerQueueSize) //
.producerName(getProducerName());`

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the producer and schema-admin commands described with Schema.JSON(String.class) and Schema.AUTO_PRODUCE_BYTES(). Trace schema handling from those entry points, including the geo-replication producer, and compare the behavior with Schema.STRING. Done means the AUTO_PRODUCE_BYTES producer succeeds and pulsar-admin schemas get returns the schema without the Not a JSON Object exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.