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

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

问题描述

我们正在尝试使用wso2 api管理器来访问我们的一些RESTful服务. 其余服务需要json负载.当json请求发送到api管理器时,它将json请求转换为xml,并在转发到实际端点时再次将其转换回json. 在我们的一种情况下,生成的json与原始请求不完全匹配. 例如,如果rquest包含一个元素数组,并且在该数组中仅传递了一个元素,则当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管理器发送的请求是

the request sent by api manager was

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

}

在实体元素下删除了数组包装. 如果元素数大于一个,则保留数组字符.

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天全站免登陆