Spring Cloud Consumer参数有效负载始终获取字节数组对象

时间:2018-10-31 12:53:05

标签: spring-cloud spring-cloud-stream spring-cloud-dataflow

我正在使用Spring Cloud Edgware。 SR3和Spring Cloud Stream 2.0.1版本。

我已经使用Spring Cloud Stream 2.0创建了testprocessor应用程序。     创建了示例流:

stream create TEST1 --definition "http --server.port=8888 | testprocessor | uploader --spring.cloud.stream.bindings.input.contentType='text/plain1' "

部署在Spring Cloud本地服务器中。

//testprocessor apps method signature is
@StreamListener(Processor.INPUT)
@sendto(Processor.OUTPUT)
public String transform(Object payload) {

}

在此应用程序的application.properties中,我已经配置了以下属性 spring.cloud.stream.bindings.input.content-type=application/json;

样本输入数据:

http post --contentType 'application/json' --data '{\"isbn\": \"1599869772", "title": "The Art of War", "author": "Sun Tzu"}' --target http://localhost:8888

当我发布上述示例数据时,我总是得到对象有效负载是byte[]对象,例如[B@5b2ff6e7,但没有得到实际的JSON字符串。 请您帮忙解决这个问题?

注意:如果我使用Spring Cloud Stream 1.3.1版本构建相同的testprocessor应用程序。一切正常。我正在获取JSON字符串。为什么使用Spring Cloud Stream 2.0.1无法正常工作

1 个答案:

答案 0 :(得分:1)

transformer应用程序具有一个expression选项,因此您可以这样做:

--expression='new String(payload)'

然后您将在public String transform(Object payload)方法中获得一个JSON字符串。

相关的GH问题:https://github.com/spring-cloud-stream-app-starters/transform/issues/6