wso2 API 管理器中的 json 转换问题 [英] json conversion issue in wso2 API Manager

查看:35
本文介绍了wso2 API 管理器中的 json 转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用 wso2 api 管理器来访问我们的一些 RESTful 服务.其余服务需要一个 json 负载.当 json 请求发送到 api 管理器时,它会将 json 请求转换为 xml,并在转发到实际端点时再次将其转换为 json.在我们的一种情况下,生成的 json 与原始请求不完全匹配.例如,如果请求包含一个元素数组,并且数组中只传递一个元素,那么当 api 管理器将请求转发到端点时,数组字符 ([,]) 将被删除.例如.我们最初的请求是

We are trying to use wso2 api manager to access some of our RESTful services. The rest services expect a json payload. When json request is sent to api manager it converts the json request to xml and again while forwarding to the actual endpoint it converts to json back. The resulting json is not matching exactly the original request in one of our cases. For instance if the rquest contains an array of elements and if only one element is passed in the array then when api manager forwards the request to the endpoint the array characters ([,]) are removed. eg. our original request was

{
    "entities": [
    {
        "name":"KK71CP20000523A1",
        "descr":"VaS",
        "mnf":"BCT",
        "mdlyr":"2012"
    }
    ]
}

api manager 发送的请求是

the request sent by api manager was

{
    "entities": 
    {
        "name":"KK71CP20000523A1",
        "descr":"VaS",
        "mnf":"BCT",
        "mdlyr":"2012"
    }

}

实体元素下的数组包装被删除.当元素个数大于1时,保留数组字符.

The array wrapping is removed under entities element. When the number of elements is more than one then the array characters are retained.

我们之前在 ESB 中也遇到过同样的问题.但是我们通过扩展默认的 JSONMessageFormatter 并使用 jettison 库中提供的 seriliazeAsArray 方法解决了这个问题.但是我们不想在 API Manager 中进行这种定制.有没有更好的方法来解决这个问题?wso2 有没有补丁可以解决这个问题?

We faced the same issue in ESB as well previously. But we worked around the issue by extending the default JSONMessageFormatter and using the seriliazeAsArray method available in the jettison library. But we dont want to do this customization in API Manager. Is there a better way of fixing this issue? Any patch available from wso2 to fix this?

推荐答案

所有 carbon 产品都带有相同的消息生成器和格式化程序,对于您的情况,您可以使用 JSONStreambuilder 和格式化程序进行检查.看看这个参考

All carbon products comes with same message builders and formatters, for your case can you check with JSONStreambuilder and formatter. Look at this reference,

这篇关于wso2 API 管理器中的 json 转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆