Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

ISSUE-3762: Shading Avro in pulsar-client #470

Closed
sijie opened this issue Dec 27, 2019 · 0 comments
Closed

ISSUE-3762: Shading Avro in pulsar-client #470

sijie opened this issue Dec 27, 2019 · 0 comments

Comments

@sijie
Copy link
Member

sijie commented Dec 27, 2019

Original Issue: apache#3762


Describe 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:

https://github.com/jerrypeng/TestAvro

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant