on 06-15-2016 6:22 PM
Finally heard from SAP.
Array for single elements is available with newer Support Packages. Please see note 2175218.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Saif,
In communication channel configuration, in XML/JSON conversion rules section, XML namespace and prefix of the element 'events' are missing - please specify them and test again.
Regards,
Vadim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Saif
What my guess is that it should be mandatory as while conversion the adapter never connects with ESR to verify the metadata hence does not have clue on what type of field is converted to what. It's totally on basis what information you have provided in XML/JSON Conversion. Neither adapter uses the XPATH to verify the field while conversion.So while conversion the adapter should know at what level of data the conversion is taken place and to what format. And namespace and prefix is the only way to know that apart from XPATH.
Eg. Suppose in above situation you have two events field defined but at different level in data. One field you have defined with only one occurrence and lies within element Payment then just by providing name do you think you can convert the above xml to right JSON.
Now irrespective of case whether its mandatory or not, you can use XSLT Mapping and introduce namespace and prefix in the data and hence can use the XML/JSON Conversion.
- Abhishek
Hello Saif,
In your XML message, the element 'events' is a root element, and as per XML specification, the well formed XML document can have one and only one root element.
To overcome this issue, I suggest you using one of nested elements of the XML document as array entries - looking into the XML document, the element 'data' is suitable for this role:
<events>
<data>
<eventContext>
...
</eventContext>
...
</data>
<data>
<eventContext>
...
</eventContext>
...
</data>
</events>
Or alternatively, you can slightly change name of the child element 'data' to 'event' so that it is more consistent with the root element name:
<events>
<event>
<eventContext>
...
</eventContext>
...
</event>
<event>
<eventContext>
...
</eventContext>
...
</event>
</events>
Following this approach, special handling can be enabled for 'data' (in the first case) or 'event' (in the second case) so that they are treated as arrays by REST adapter during XML/JSON conversion.
Regards,
Vadim
So I finally got it working but will check with SAP for some clarification.
As per following SAP document(http://help.sap.com/saphelp_nw73ehp1/helpdata/en/a4/0979890af3403d84ff2f028ffec5d9/content.htm) ,
namespace is only required if there are more than 2 elements with same name (since I only had one, I did not give namespace).Secondly, array is only created if there are more than one occurrence of same element. If the element occurs only once, array won't be created (I don't like this so will check with SAP on it).
I did a duplicate subtree in message mapping (thereby creating multiple "events" tag in XML) and it created array in JSON. Our external vendor is fine with receiving same JSON twice but I don't think it's the best solution.
Will update the ticket with SAP's response.
Thanks
Hi Saif,
I had a similar requirement and ultimately decided to go for Java mapping to create JSON content, specially considering my output structure was very small (8-10 fields at the most). And in the communication channel I didn't perform any conversion.
Hope this is useful for anyone else looking for similar solution.
Regards,
Sanjeev.
I like Sanjeev's answer.
On a PI 7.1 server we had to convert JSON to XML and ended up using a Java Mapping.
All we had to do was use the org.json.JSONObject class from json.org and with 2 lines of code, our JSON was converted to XML.
//inputStreamString is the JSON as a String.
// Use Java your normal Java Mapping Techniques to convert InputStream to String
JSONObject o = new JSONObject(inputStreamString);
String xml = org.json.XML.toString(o);
I ran the your JSON examples through this and it works like a charm!
Regards,
Bhavesh
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.