vpeddada opened a new issue, #20274:
URL: https://github.com/apache/pulsar/issues/20274

   ### Search before asking
   
   - [X] I searched in the [issues](https://github.com/apache/pulsar/issues) 
and found nothing similar.
   
   
   ### Version
   
   Java Client(2.11.0)-->broker(2.11.0)
   Broker instance OS: Amazon Linux 2023
   Java App running OS : Windows 10
   
   ### Minimal reproduce step
   
   - Enable **isSchemaValidationEnforced** on the pulsar instance.
   - Use the following code snippet to build schema definition and send the 
message.
   
   ```
        String jsonSchemaDef= "{"name" : "Employee", "fields" : [{ "name" : 
"Name" , "type" : "string" }, { "name" : "Age" , "type" : "int" }]}";
        JSONObject schemaDefObj = new JSONObject(jsonSchemaDef);
        JSONArray fArray = schemaDefObj.getJSONArray("fields");                 
                
        RecordSchemaBuilder recordSchemaBuilder = 
SchemaBuilder.record(schemaName);
        for(int i=0;i<fieldArray.length();i++) {
                JSONObject fieldObj = fieldArray.getJSONObject(i);
                
recordSchemaBuilder.field(fieldObj.getString("name")).type(SchemaType.valueOf(fieldObj.getString("type")type.toUpperCase()));
   // Create the record builder by parsing through a JSON  String               
   
        }               
        SchemaInfo schemaInfo = 
recordSchemaBuilder.build(SchemaType.valueOf("JSON")); // Setting the type of 
the schemaDef to JSON.
        Producer<GenericRecord> producerJson = 
pulsarclient.newProducer(Schema.generic(schemaInfo))
                                                                
.topic(topicName)                                                               
                                                                .create();
        GenericSchemaImpl schema = GenericJsonSchema.of(schemaInfo);
        GenericRecordBuilder recordbuilder =schema.newRecordBuilder();          
        
        String message ="{"Employee":{"Age" :35,"Name" 
:"TestUser","Mobile":123469870}}"; // Added an extra field Mobile in the 
payload.
        JSONObject payloadObj = new JSONObject(message);                        
                
        Set<String> fieldSet =payloadObj.keySet();                              
        for (String key1 : fieldSet) {                                          
        
                        recordbuilder.set(key1, 
payloadObj.getJSONObject(key1).toMap()); //Building the payload using 
GenericRecord builder to send the message
        }
        GenericRecord fieldrecord= rcbuilder.build();
        MessageId msgId =producerAvro.newMessage().value(fieldrecord).send();
                                        
   ```
   
   ### What did you expect to see?
   
   As the message payload contains extra parameter Mobile the pulsar broker 
should reject the message and throw an error.
   
   ### What did you see instead?
   
   The message is acknowledged by the broker and send operation is successful.
   
   ### Anything else?
   
   We tried the same case with Avro schema type and it throws an error if any 
extra parameter is passed in the message payload.
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


-- 
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]

Reply via email to