简体   繁体   中英

json conversion issue in wso2 API Manager

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"
    }
    ]
}

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.

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM