JasonS JasonS - 6 months ago 83
Java Question

Spring Cloud Stream: JSON array cannot be cast to POJO list

I'm doing some tests of the content type auto-conversion of Spring Cloud Stream.

As the spring-cloud-stream Guide shows. The json format of

{"greeting":"Hello, world"}
) will be cast to POJO
object automatically when consumes in the
. This tests successfully.

But, when i change the output as
List<GreetingMessage > [{"greeting":"Hello, world"}, {"greeting":"Good morning"}]
, the input WILL NOT cast it to POJO
List<GreetingMessage >
objects, but as POJO

So my question is:

  • Is this an existing issue or am i doing something wrong?


public class GreetingMessage {
private String greeting;

public class GreetingSource {

@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource<List<GreetingMessage>> greeting() {
return new MessageSource<List<GreetingMessage>>() {
public Message<List<GreetingMessage>> receive() {
return new GenericMessage(Arrays.asList(new GreetingMessage("hello"), new GreetingMessage("hello2")));

public class GreetingSink {
public void receive(Message<List<GreetingMessage>> msg) {
// handle GreetingMessage


This is a limitation of the message conversion process, where the parameterized type is not considered (just the raw List type). Please open an issue GitHub if you think this needs to be supported.