Shading Avro in pulsar-client
See original GitHub issueDescribe the bug
Because we shade Avro in the pulsar-client, the ReflectData API to get a schema from a POJO fails to get the correct schema for generated Avro java classes
To Reproduce
Given an avro schema:
{
"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "favorite_number",
"type": [
"int",
"null"
]
},
{
"name": "favorite_color",
"type": "string"
},
{
"name": "age",
"type": "int",
"default": 19
}
]
}
Passing the generated java class from the above schema to the AvroSchema in pulsar-client produces the following result:
System.out.println(new String(org.apache.pulsar.client.impl.schema.AvroSchema.of(User.class).getSchemaInfo().getSchema()));
outputs:
{"type":"record","name":"User","namespace":"example.avro","fields":[{"name":"name","type":["null","string"],"default":null},{"name":"favorite_number","type":["null","int"],"default":null},{"name":"favorite_color","type":["null","string"],"default":null},{"name":"age","type":"int"}]}
which is incorrect while
System.out.println(ReflectData.get().getSchema(User.class));
outputs the correct schema that matches the original schema:
{"type":"record","name":"User","namespace":"example.avro","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":"string"},{"name":"age","type":"int","default":19}]}
Here is the line in Avro responsible for getting the schema from generated classes: https://github.com/apache/avro/blob/release-1.8.2/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java#L277
Here is a project I created that demonstrates this problem:
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Pulsar Java client
Both pulsar-client and pulsar-client-admin are shaded packages and they shade dependencies independently. Consequently, the applications using both ...
Read more >[pulsar] 04/04: [Schema] Fix parse BigDecimal (#14019)
getRecommendedSchema(Conversions.java:73) ~[pulsar-client-2.8.1.jar:2.8.1] at org.apache.pulsar.shade.org.apache.avro.reflect.ReflectData.
Read more >Is there any way to use Pulsar with schema registry via ...
Currently, there isn't a way to specify the schema when creating a WS producer/consumer. The best option is to specify the AVRO schema...
Read more >org.apache.pulsar : pulsar-client : 2.8.1 - Maven Central Repository ...
Pulsar Client Java. ... org.apache.pulsar:pulsar-client 2.8.1. content_copy. <?xml version="1.0" encoding="UTF-8"?> ...
Read more >pulsar-client-2x-shaded » 2.4.2 - Maven Repository
Category/License Group / Artifact Version Up...
Annotation Lib Apache 2.0 com.fasterxml.jackson.core » jackson‑annotations 2.9.9 2.1...
JSON Lib Apache 2.0 com.fasterxml.jackson.core » jackson‑core 2.9.9 2.1...
Compression BSD...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vzhikserg Thanks, that will work for me, though an underlying Avro upgrade probably would have been a good time to uncouple the Avro version from Pulsar to avoid this same problem in the future…
I’d like to at least have the option to use the Java Pulsar client with an unshaded Avro. We use Avro extensively with Kafka, and while we migrate to Pulsar, its imperative we have compatibility at the Avro message level, which means using the same version of Avro.
Here is an issue we are running into because our messages use Avro 1.9.1 which supports the java.time APIs: