0

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 GreetingMessage({"greeting":"Hello, world"}) will be cast to POJO GreetingMessage object automatically when consumes in the @StreamListener. 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 List<String>.


So my question is:

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

Code:

@Data
@AllArgsConstructor
public class GreetingMessage {
    private String greeting;
}

@EnableBinding(Source.class)
public class GreetingSource {

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

@EnableBinding(Sink.class)
public class GreetingSink {
    @StreamListener(Sink.INPUT)
    public void receive(Message<List<GreetingMessage>> msg) {
        // handle GreetingMessage
        System.out.println(msg);
    }
}
JasonS
  • 445
  • 1
  • 5
  • 17

1 Answers1

1

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.

Marius Bogoevici
  • 2,380
  • 1
  • 13
  • 14
  • [Issue](https://github.com/spring-cloud/spring-cloud-stream/issues/726) on Github submitted. – JasonS Dec 01 '16 at 01:03