MaitreyaBuddha opened a new issue #8215:
URL: https://github.com/apache/pulsar/issues/8215


   **Describe the bug**
   I am sending objects with a timestamp of type `Instant`. When using a 
`JsonSchema` for my defined message object, it fails to deserialize the 
`Instant` field.
   This is because the internal `ObjectMapper` is not configured to deserialize 
using `mapper.registerModule(new JavaTimeModule());`
   
   **To Reproduce**
   Steps to reproduce the behavior:
   1. Create a consumer using `JsonSchema` with a class that has a member of 
type `Instant`
   2. Create a producer with the same `JsonSchema`
   3. Send a message with producer
   4. When the consumer calls `message.getValue()`
   5. Then see 
   ```
   org.apache.pulsar.client.api.SchemaSerializationException: 
org.apache.pulsar.shade.com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
 Cannot construct instance of `java.time.Instant` (no Creators, like default 
construct, exist): no String-argument constructor/factory method to deserialize 
from String value ('2020-10-06T14:35:40.089034-06:00')
    at [Source: (byte[])\"{\"timestamp\": 
\"2020-10-06T14:35:40.089034-06:00\"}\"; line: 1, column: 270] (through 
reference chain: <redacted>[\"timestamp\"])
    
org.apache.pulsar.client.impl.schema.reader.JacksonJsonReader.read(JacksonJsonReader.java:49)
   ```
   
   **Expected behavior**
   The object should deserialize without error.
   
   **Workaround**
   Use a `String` and deserialize yourself.
   
   **Proposed Fix**
   Add `mapper.registerModule(new JavaTimeModule());` inside `JSONSchema` 
initialization.
   
   **Desktop (please complete the following information):**
   N/A
   
   **Additional context**
   I am aware that there is an `InstantSchema`, that's not the use case I am 
seeking. This is an example of a `JsonSchema` with an object having a nested 
`Instant` field.
   
   This seems like a common use case that someone would have encountered 
before, although I did not find references in any open issues. Apologies if I 
have missed some previous discussion.
   
   I have a fix and am trying to test it. This actually exposed two other items 
I would explore making PRs/Issues for:
   1: This also causes moving to DLQ to fail because something internal tries 
to deserialize when moving the message. The message is then retried 
indefinitely. My next step here would be to find or make an issue for this.
   2. Adding `Instant` to the test's serialized object `Foo` breaks a lot of 
unrelated tests. I also noticed some expected/actual are swapped with ambiguous 
argument names in helper functions. My next step here would be make a new 
feature ticket and start working on a refactor PR to precede the fix for this 
ticket.
   
   I would appreciate if anyone more familiar with the project can advise on if 
this plan sounds good, or what the best path would be.
   
   Thanks!


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