spring-cloud / spring-cloud-function

Apache License 2.0
1.04k stars 618 forks source link

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

Closed acisternino closed 1 month ago

acisternino commented 3 months ago

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

Examples for 4.1.3 (in 2023.0.3):

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 commented 3 months ago

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

acisternino commented 3 months ago

Yes, but I might need a couple of days.

acisternino commented 3 months ago

Here it is:

olegz commented 1 month ago

Sorry for the delay, will be addressing it this week

sobychacko commented 1 month ago

Related issue: https://github.com/spring-cloud/spring-cloud-stream/issues/2980

olegz commented 1 month ago

I am closing it as it is duplicate to https://github.com/spring-cloud/spring-cloud-stream/issues/2980

acisternino commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Let me read it again

olegz commented 1 month ago

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