Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in serialization format for j.u.Date and java.time classes #1189

Closed
acisternino opened this issue Jul 29, 2024 · 11 comments
Closed

Change in serialization format for j.u.Date and java.time classes #1189

acisternino opened this issue Jul 29, 2024 · 11 comments
Assignees
Labels
Milestone

Comments

@acisternino
Copy link

The following happens when working with a RabbitMQ message broker.

Investigating an exception thrown from within the deep bowels of Spring Cloud Stream I have come across a weird change between 4.1.2 and 4.1.3.

The JSON serialization format of any Date/Time related class has changed from a ISO 8601-like String to a unix timestamp.

The following examples are for an hypothetical ts property of different Java types and the values are directly copied from the message received in the queue.

Examples for 4.1.2 (in 2023.0.2):

  • j.u.Date: "ts": "2024-07-29T09:21:40.206+00:00"
  • j.t.Instant: "ts": "2024-07-29T09:20:15.002750Z"
  • j.t.ZonedDateTime: "ts": "2024-07-28T14:46:27.0000005+02:00"

Examples for 4.1.3 (in 2023.0.3):

  • j.u.Date: "ts": 1722253394807
  • j.t.Instant: "ts": 1722253298.240253000
  • j.t.ZonedDateTime: "ts": 1722170787.000000500

Another peculiar choice is that j.u.Date is now serialized as milliseconds while java.time classes as seconds with a decimal part.

The code I used to generate a message is the following:

// Object containing a few time-related properties
var domObj = new ObjectWithDates();

Message<ObjectWithDates> payload = MessageBuilder.withPayload(domObj).build();

// Simple output binding configured in application.yml
// StreamBridge is the default one
streamBridge.send("testError-out-0", payload);

The sample project I used to investigate uses Java 21 and has the following dependencies:

implementation(platform("org.springframework.boot:spring-boot-dependencies:3.3.2"))
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")

implementation(platform("org.springframework.cloud:spring-cloud-dependencies:2023.0.2"))  // or 2023.0.3
implementation("org.springframework.cloud:spring-cloud-starter-stream-rabbit")
@sobychacko
Copy link
Collaborator

@acisternino, could you provide a minimal application where we can reproduce the issue? Thanks!

@acisternino
Copy link
Author

Yes, but I might need a couple of days.

@acisternino
Copy link
Author

@olegz olegz self-assigned this Sep 25, 2024
@olegz
Copy link
Contributor

olegz commented Sep 25, 2024

Sorry for the delay, will be addressing it this week

@sobychacko
Copy link
Collaborator

Related issue: spring-cloud/spring-cloud-stream#2980

@olegz
Copy link
Contributor

olegz commented Oct 7, 2024

I am closing it as it is duplicate to spring-cloud/spring-cloud-stream#2980

@olegz olegz closed this as completed Oct 7, 2024
@acisternino
Copy link
Author

I am sorry but this has nothing to do with spring-cloud/spring-cloud-stream#2980.

This one is about a change in default serialization format for many time-related classes from one version to the next.

No Jackson annotations are involved.

This should be reopened

@olegz olegz reopened this Oct 10, 2024
@olegz
Copy link
Contributor

olegz commented Oct 10, 2024

Could you provide a sample or better explain what exactly you are looking for? You use the same sample, hence my assumption that they are the same, but i may be wrong

@acisternino
Copy link
Author

Yes you are right, the sample project is used for both issues but each one can be triggered by using a different endpoint.

ATM I have very limited internet access. IIRC everything is explained in the project's readme

@olegz
Copy link
Contributor

olegz commented Oct 10, 2024

Let me read it again

@olegz
Copy link
Contributor

olegz commented Oct 16, 2024

I see the issue, will transfer it to spring-cloud-function

@olegz olegz transferred this issue from spring-cloud/spring-cloud-stream Oct 16, 2024
@olegz olegz added this to the 4.1.4 milestone Oct 16, 2024
@olegz olegz added the bug label Oct 16, 2024
olegz added a commit that referenced this issue Oct 16, 2024
@olegz olegz closed this as completed in 63cdb68 Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants