首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Cloud Consumer参数有效负载始终获取字节数组对象

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

Stack Overflow用户
提问于 2018-10-31 20:53:05
回答 1查看 474关注 0票数 1

我使用的是Spring Cloud Edgware。SR3和Spring Cloud Stream 2.0.1发布。

我使用spring cloud stream 2.0创建了测试处理器应用程序。创建了样本流:

代码语言:javascript
复制
stream create TEST1 --definition "http --server.port=8888 | testprocessor | uploader --spring.cloud.stream.bindings.input.contentType='text/plain1' "

部署在Spring云本地服务器上。

代码语言:javascript
复制
//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;

输入数据示例:

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

当我发布上面的示例数据时,我总是得到对象有效负载是像[B@5b2ff6e7这样的byte[]对象,而不是得到实际的JSON字符串。你能在这个问题上提供帮助吗?

注意:如果我使用spring cloud stream 1.3.1版本构建相同的测试处理器应用程序。它工作得很好。我正在获取JSON字符串。为什么使用spring cloud stream 2.0.1不能工作

EN

回答 1

Stack Overflow用户

发布于 2018-10-31 22:05:03

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

代码语言:javascript
复制
--expression='new String(payload)'

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53083818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档