BewareMyPower commented on issue #9483:
URL: https://github.com/apache/pulsar/issues/9483#issuecomment-776086957


   From the comparison between Java and Python. It looks like Python client 
doesn't generate a right schema bytes. Here's the Java client code for tests:
   
   ```java
   @NoArgsConstructor
   @AllArgsConstructor
   @Getter
   @Setter
   class Apex {
       private Map<String, List<String>> values;
   }
   
   public class SchemaDemo {
       public static void main(String[] args) {
           try (PulsarClient pulsarClient = 
PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()) {
               Producer<Apex> producer = pulsarClient
                       .newProducer(Schema.AVRO(Apex.class))
                       .topic("example")
                       .create();
               producer.close();
           } catch (PulsarClientException e) {
               e.printStackTrace();
           }
       }
   }
   ```
   
   And it works well.
   
   Compare these two schema string (they are both formatted).
   
   1. Java
   
   ```json
   {
     "type": "record",
     "name": "Apex",
     "fields": [
       {
         "name": "values",
         "type": [
           "null",
           {
             "type": "map",
             "values": {
               "type": "array",
               "items": "string",
               "java-class": "java.util.List"
             }
           }
         ],
         "default": null
       }
     ]
   }
   ```
   
   2. Python
   
   ```json
   {
     "name": "Apex",
     "type": "record",
     "fields": [
       {
         "name": "values",
         "type": [
           "null",
           {
             "type": "map",
             "values": "array"
           }
         ]
       }
     ]
   }
   ```
   
   The key difference is the type of array item, in Python it's just
   
   ```json
             "values": "array"
   ```
   
   But in Java it's
   
   ```json
             "values": {
               "type": "array",
               "items": "string",
               "java-class": "java.util.List"
             }
   ```


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


Reply via email to