whisper-bye edited a comment on issue #2992: schemas feature request
URL: https://github.com/apache/pulsar/issues/2992#issuecomment-601623655
 
 
   @nha @merlimat 
   
   sorry for asking.
   
   In my case, I have some raw json string data send to topic and can't hard 
code pojo class, I want to use the pulsar schema feature to validation the 
structure. I have a topic "my-topic" and associated with json schema in below, 
then I try to transmission some message.
   ```
   var producer = client.newProducer(Schema.AUTO_PRODUCE_BYTES();
   producer.send("{\"y\": 1}".getBytes()); // here! the value is 1(number) not 
string.
   
   var reader = client.newReader(Schema.AUTO_CONSUME())
   var message = reader.readNext();
   I got {"y": 1}
   ```
   
   my question is how pulsar schema works? The message should be rejected.
   
   ```
   {
     "version": 1,
     "schemaInfo": {
       "name": "my-topic",
       "schema": {
         "type": "record",
         "name": "Data",
         "namespace": "com.iot.test",
         "fields": [
           {
             "name": "y",
             "type": [
               "null",
               "string"
             ]
           }
         ]
       },
       "type": "JSON",
       "properties": {
         "__alwaysAllowNull": "true"
       }
     }
   }
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to