Hi,
I want to change the responding content type based on Accept header(JSON or
XML), sent in the request. My concern is the wrapping element of arrays.
For example,
Required Json response,
[
{
"aaa" : "23432",
"bbb" : "234",
"ccc" : "asdfas"
},
{
"aaa" : "23432",
"bbb" : "234",
"ccc" : "asdfas"
},
{
"aaa" : "23432",
"bbb" : "234",
"ccc" : "asdfas"
}
]
Required XML response,
<accounts>
<account>
<aaa>2342344</aaa>
<bbb>23432432432</bbb>
<ccc>asdasdasd</ccc>
</account>
<account>
<aaa>234324</aaa>
<bbb>32432</bbb>
<ccc>asdfasdf</ccc>
</account>
<account>
<aaa>234</aaa>
<bbb>34234</bbb>
<ccc>asdf</ccc>
</account>
</accounts>
If I build local message with jsonArray and jsonElement as below, I could
get the JSON response correctly. But XML response would be wrong, as it is
not wrapped with accounts and account tags.
<jsonArray>
<jsonElement>
<aaa>2342344</aaa>
<bbb>23432432432</bbb>
<ccc>asdasdasd</ccc>
</jsonElement>
<jsonElement>
<aaa>234324</aaa>
<bbb>32432</bbb>
<ccc>asdfasdf</ccc>
</jsonElement>
<jsonElement>
<aaa>234</aaa>
<bbb>34234</bbb>
<ccc>asdf</ccc>
</jsonElement>
</jsonArray>
I'm building this message using a XSLT. I can think of using 2 XSLTs for
two types. But that will duplicate XSLT just for this. Is there a better
approach?
Thanks.
--
--
Lahiru Sandaruwan
Associate Technical Lead,
WSO2 Inc., http://wso2.com
lean.enterprise.middleware
m: +94773325954
e: [email protected] b: https://medium.com/@lahirugmg
in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev