Skip to content

Problem in deserialization when defining consumers with generics types #1251

Closed
@ferblaca

Description

@ferblaca

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");
    }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions