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

Problem in deserialization when defining consumers with generics types #3088

Open
ferblaca opened this issue Feb 26, 2025 · 0 comments
Open

Comments

@ferblaca
Copy link
Contributor

ferblaca commented Feb 26, 2025

Describe the issue
When implementing a consumer class with generic types that implement java.util.Consumer, we have observed that depending on how the consumer bean is defined, the deserialization of messages works correctly or not.

We have created this repository that describes this situation, defining the Consumer beans "correctly" or "incorrectly".

We understand that it should work both ways. Additionally, it is a good practice and recommended by Spring to define the implementation as the bean output rather than the interface.

To Reproduce
Steps to reproduce the behavior:

  1. Define a Class that implements Consumer with types variables
public class GenericConsumer<T> implements Consumer<T> {
...
}
  1. Define a bean of this class with this signature:
    @Bean
    public GenericConsumer<ProductCompleteDTO> productConsumer_KO() {
        return new GenericConsumer<>("productConsumer_KO");
    }
  1. Send a message.

Version of the framework
Spring-Boot 3.4.2
Spring Cloud 2024.0.0

Observed outcome
The message is not deserialized and arrives in byte[].
For batch mode the message payload is null in the list of messages.

Expected behavior
The message is deserialized correctly by the converter.

Additional context
The same behavior occurs for consumer in batch-mode.
Works OK when the bean is defined in this manner:

    @Bean
    public Consumer<ProductCompleteDTO> productConsumer_OK() {
        return new GenericConsumer<>("productConsumer_OK");
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant