MarvinCai opened a new issue #9605:
URL: https://github.com/apache/pulsar/issues/9605


   **Describe the bug**
   Pojo serialized with GenericJsonSchema can't be reconstruct back to original 
class.
   Code snippet:
   
   ```
       @Data
       @AllArgsConstructor
       @NoArgsConstructor
       private static class Seller {
           public String state;
           public String street;
           public long zipCode;
       }
   
       @Data
       @AllArgsConstructor
       @NoArgsConstructor
       private static class PC {
           public String brand;
           public String model;
           public int year;
           public GPU gpu;
           public Seller seller;
       }
   
       private enum GPU {
           AMD, NVIDIA
       }
   
      JSONSchema jsonSchema = 
JSONSchema.of(SchemaDefinition.builder().withPojo(PC.class).build());
      GenericSchema genericJsonSchema = 
GenericJsonSchema.of(jsonSchema.getSchemaInfo());
      PC pc = new PC("dell", "alienware", 2021, GPU.AMD, new Seller("WA", 
"street", 98004));
      String pStr = ObjectMapperFactory.getThreadLocal().writeValueAsString(pc);
      JsonNode jsonNode = ObjectMapperFactory.getThreadLocal().readTree(pStr);
      GenericJsonRecord genericJsonRecord = new GenericJsonRecord(null, null, 
jsonNode, genericJsonSchema.getSchemaInfo());
            
ObjectMapperFactory.getThreadLocal().treeToValue(((GenericJsonRecord)genericJsonSchema.decode((genericJsonSchema.encode(genericJsonRecord)))).getJsonNode(),
 PC.class);
   
   ```
   Exception was thrown:
   ```
   com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot 
construct instance of `org.apache.pulsar.broker.admin.TopicsTest$PC` (although 
at least one Creator exists): no String-argument constructor/factory method to 
deserialize from String value 
('{"brand":"dell","model":"alienware","year":2021,"gpu":"AMD","seller":{"state":"WA","street":"street","zipCode":98004}}')
    at [Source: UNKNOWN; line: -1, column: -1]
   ```
   
   **To Reproduce**
   Use above code snippet.
   
   **Expected behavior**
   Should be able to reconstruct original pojo.
   
   Suspect due to the "toString()" 
[here](https://github.com/apache/pulsar/blob/7bf7cdda1a2181c329176b403f7a60fc84f557fa/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonWriter.java#L39)
 causing json written as string first.
   


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