Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Activity event with timetstamp not having milli seconds results in com.fasterxml.jackson.databind.exc.InvalidFormatException #1502

Closed
harinandan-reddy opened this issue Dec 21, 2022 · 2 comments · Fixed by #1503
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository.

Comments

@harinandan-reddy
Copy link
Contributor

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Version

4.14.2

Describe the bug

We some time receive activity event with timetstamp not having milli seconds like 2022-09-23T09:19:29Z which results in the following error

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.OffsetDateTime` from String "2022-09-23T09:19:29Z": Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) Text '2022-09-23T09:19:29Z' could not be parsed at index 19; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.OffsetDateTime` from String "2022-09-23T09:19:29Z": Failed to deserialize java.time.OffsetDateTime: (java.time.format.DateTimeParseException) Text '2022-09-23T09:19:29Z' could not be parsed at index 19 at [Source: (PushbackInputStream); line: 1, column: 57] (through reference chain: com.microsoft.bot.schema.Activity["timestamp"])]

To Reproduce

Steps to reproduce the behaviour:

Run the following unit test to reproduce the error

import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import com.microsoft.bot.schema.Activity;
import java.io.IOException;
import org.junit.jupiter.api.Test;

class ActivityTest {

  @Test
  void testActivityDeserialize() throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JSR310Module());
    String json =
        "{\"fromStreamingConnection\":false,\"teamsActivity\":false,\"type\":\"message\",\"timestamp\":\"2022-09-23T09:19:29Z\",\"historyDisclosed\":false}";
    assertNotNull(objectMapper.readValue(json, Activity.class));
  }
}

Expected behaviour

The Activity object should be deserialised without any error

Screenshots

NA

Additional context

NA

@harinandan-reddy harinandan-reddy added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Dec 21, 2022
@harinandan-reddy
Copy link
Contributor Author

Changing the annotation on Activity timestamp field should help resolve the issue

@JsonProperty("timestamp")
@JsonInclude(Include.NON_EMPTY)
@JsonFormat(
  shape = Shape.STRING,
  pattern = "yyyy-MM-dd'T'HH:mm:ss[.n]XXX",
  timezone = "UTC"
)
private OffsetDateTime timestamp;

@johnataylor
Copy link
Member

Please go ahead and submit a PR for your proposed fix, linking it to this issue. Thanks.

@johnataylor johnataylor added customer-reported Issue is created by anyone that is not a collaborator in the repository. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. and removed needs-triage The issue has just been created and it has not been reviewed by the team. labels Dec 21, 2022
harinandan-reddy pushed a commit to harinandan-reddy/botbuilder-java that referenced this issue Dec 22, 2022
tracyboehrer pushed a commit that referenced this issue Jan 12, 2023
Co-authored-by: Harinandan Chintamreddy <hchintamreddy@axiamatic.com>
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants