jerrypeng edited a comment on issue #3741: POJO AvroSchema always allowNull
URL: https://github.com/apache/pulsar/issues/3741#issuecomment-469540392
 
 
   @sijie @skyrocknroll I just experimented a little.
   
   Given the schema that @skyrocknroll posted on the pulsar chat as an example:
   
   ```
   {
     "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
       }
     ]
   }
   ```
   
   I did some tests using the generated java class with the ReflectData schema 
generator:
   
   ```
   log.info("{}", new 
String(AvroSchema.of(User.class).getSchemaInfo().getSchema()));
   
   log.info("{}", ReflectData.get().getSchema(User.class));
   
   log.info("{}", ReflectData.AllowNull.get().getSchema(User.class));
   ```
   
   They all produced the same result:
   
   ```
   21:07:27.741 [main:org.company.Test4@44] INFO  org.company.Test4 - 
{"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}]}
   
   21:07:27.746 [main:org.company.Test4@46] INFO  org.company.Test4 - 
{"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}]}
   
   21:07:27.746 [main:org.company.Test4@48] INFO  org.company.Test4 - 
{"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}]}
   ```
   
   regardless of  whether AllowNull is set or not the Avro schema generated is 
the same as the one in the Avro schema file.  The ReflectData implementation is 
probably getting the schema from the generated java class via 
```getClassSchema()``` as @merlimat suggested before.  So my question still 
holds what exactly does removing AllowNull change?
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to