spring-cloud / spring-cloud-function

Apache License 2.0
1.04k stars 618 forks source link

Missing Fields Causing ClassCastException - Json Deserialization Issue #1180

Closed ferblaca closed 2 months ago

ferblaca commented 2 months ago

Describe the bug We are getting an error when consuming/deserializing a java object that contains less fields than the object sent by the producer.

This behavior started from Spring Cloud version 2023.0.1 and continues to be reproduced in version 2023.0.3.

We are getting the real problem when deserializing with Spring Cloud Stream Kafka a distributed traceability message that is being sent with zipkin via kafka sender, but the demo we show you reproduces the problem anyway.

Attached is a sample application in which the problem is reproduced: https://github.com/ferblaca/demoSCSKafka

The demo application consists of sending a ProductCompleteDTO POJO with a Kafka producer configured with the Kafka client (without SCS) and two SCS Kafka consumers: one deserialising the message to ProductCompleteDTO and the other to ProductSimpleDTO (a subset of the ProductCompleteDTO object).

In Spring Cloud version 2023.0.0, both consumers correctly deserialize the message to their corresponding classes, but from version 2023.0.1-2023.0.3 onwards only the consumer that expects exactly the same object being sent consumes correctly.

This for us is a behavioural change that may be related to issue #1161.

Sample

https://github.com/ferblaca/demoSCSKafka

Steps to report the problem:

  1. Start the DemoStreamKafkaApplication.
  2. Check that the consumer completeConsumer consumes the sent message correctly.
  3. Check for a ClassCastException error in the simpleConsumer.

The same application can be verified to work correctly by configuring version 2023.0.0 or by setting the application property demo.jackson.mapper.enabled: true by which a custom JacksonMapper is configured.

olegz commented 2 months ago

Can you please upgrade spring-cloud-function-context to 4.1.4-SNAPSHOT as this issue has been addressed already. You can simply add this to your POM

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-context</artifactId>
            <version>4.1.4-SNAPSHOT</version>
 </dependency>

I tested it and it works

ferblaca commented 2 months ago

Can you please upgrade spring-cloud-function-context to 4.1.4-SNAPSHOT as this issue has been addressed already. You can simply add this to your POM

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-context</artifactId>
            <version>4.1.4-SNAPSHOT</version>
 </dependency>

I tested it and it works

That's right, it works with this version . I understand it will be available for Spring Cloud version 2023.0.4 right?

olegz commented 2 months ago

Correct. I am closing it

SabareeshGC commented 1 month ago

@olegz Is there an release date for spring cloud 2023.0.4 . We are affected by this bug as well.

CharliePrm88 commented 3 weeks ago

@olegz any news about 2023.0.4?