shibd opened a new pull request, #20741:
URL: https://github.com/apache/pulsar/pull/20741
### Motivation
If a producer use `Schema.JSON(String.class)` schema, es sink connector will
throw `ClassCastException`.
1. Create a producer.
```java
Producer<String> producer = client.newProducer(Schema.JSON(String.class))
.topic("test-es")
.create();
MessageId msgID = producer.send({\"a\":1});
```
2. When es sink connector handle this message, it will throw
`ClassCastException`.
```
java.lang.ClassCastException: class java.lang.String cannot be cast to class
com.fasterxml.jackson.databind.JsonNode (java.lang.String is in module
java.base of loader 'bootstrap'; com.fasterxml.jackson.databind.JsonNode is in
unnamed module of loader 'app')
```
Exception throws on here:
https://github.com/apache/pulsar/blob/593fcb87b6d3bd6401eb4ffa4c25d8b3f724e49d/pulsar-io/elastic-search/src/main/java/org/apache/pulsar/io/elasticsearch/ElasticSearchSink.java#L382
The root cause is when the schema is not `RECORD` type, it will not transfer
to `JsonNode`.
https://github.com/apache/pulsar/blob/af1360fb167c1f9484fda5771df3ea9b21d1440b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoConsumeSchema.java#L204-L220
### Modifications
- When `navtiveObject` is String, try to transfer it to JsonNode.
### Verifying this change
- Add `sendJsonStringSchemaTest ` to cover it.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update
later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]