【问题标题】:How to convert JSON body to text in WSO2如何在 WSO2 中将 JSON 正文转换为文本
【发布时间】:2019-05-16 06:30:45
【问题描述】:

我正在尝试创建一个字符串属性,其中包含我在正文中发送的 JSON。

问题是,如果我发送带有标题“Content-Type”的 json:“text/plain”,那就完美了。但是,如果我使用 'Content-Type': 'application/json' 发送它,我认为它会尝试将其转换为 xml。

这适用于 Linux 服务器,wso2 EI 6.4.0

这是我要发送的 JSON:
{ "hello": "isJson" }

并且在字符串中使用标题 Content-Type: 'application/json' 我只得到这个:isJson

但是当我使用 Content-Type: 'text/plain' 发出请求时,结果是这样的:{"hello": "isJson"}。

如何使用 Content-Type: application/json 获得相同的结果?

谢谢

【问题讨论】:

  • I get only this: isJson - 你从哪里得到的?怎么样?
  • 当消息到达时,我把这个属性转换为文本 但看到它有更改属性后的正文如下所示:isJson

标签: wso2 wso2esb wso2ei


【解决方案1】:

这是因为 EI 在内部以 XML 格式表示负载。 当您使用 text/plain EI 调用时,将其放在两个“文本”标签中,如下所示

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">{ "hello": "isJson" }</text></soapenv:Body></soapenv:Envelope>

注意 { "hello": "isJson" } 被保留。

当您使用 application/json 调用时,EI 会将其转换为 XML,如下所示

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><hello>isJson</hello></jsonObject></soapenv:Body></soapenv:Envelope>

当您将 body 丰富到 property 时,两种不同的表示会丰富到 body,如上所示。

我们通过将原生 JSON 支持引入到 Enrich 调解器来对此消息流进行了一些改进。您可以从即将发布的 EI 6.5.0 版本中获得预期的行为。

【讨论】:

  • 您好,感谢您的快速回复。最后我用一个指示媒体类型的payloadFactory解决了这个问题:文本和在args中我设置了$。 (所有的json)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-10
  • 2020-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-12
相关资源
最近更新 更多