on 01-06-2021 12:12 PM
Hi,
CPI is sending JSON message as given below after message mapping and XML to JSON converter.
{
"EmpNr": "1234",
"EmpDetails":""
}
But, The SAP OData service works if JSON message is as given below. OData service works if EmpDetails have empty value in brackets [].
{
"EmpNr": "1234",
"EmpDetails": []
}
How can we convert "EmpDetails":"" to "EmpDetails": [] when sending JSON message to SAP OData service. Can anyone help in this.
Hi vijayant.jha2,
please try below code:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper
def Message processData(Message message) {
def body = message.getBody(String);
def slurper = new JsonSlurper().parseText(body)
def empNr = slurper.EmpNr
def str = []
def builder = new groovy.json.JsonBuilder()
builder.root{
EmpNr "$empNr"
EmpDetails "$str"
}
message.setBody(builder.toString());
return message;
}
Hope this helps !
thanks and regards,
Praveen T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
tirumareddy.praveen - Thanks for the script. It converts to array successfully. But when I post JSON to OData receiver,I am getting below error -
Error Details
com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: Request Payload Parsing Failed for one of the reason: (1) Either the OData metadata content available in the server is outdated OR (2) The request payload seems to be incorrect. Error Details : only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1) , org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1) .
The MPL ID for the failed message is :
For more details please check tail log.
Any idea on this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello vijayant.jha2 , glad to hear that it worked for you.
Being a programmer, which I also am, it is always easier to work with scripts and code.
BUT in my opinion, the CPI, the users and also the customers benefit the most when the given on-board tools are used (ex: Content Modifier, Converter etc.). This way the maintenance is much easier and also the customer is more happy about a graphically readable result than about script snippets. Even if it is sometimes a bit more challenging to use the on-board tools, if you can avoid the use of a script, it is worth it.
I wish you all the best
Dennis
Hi vijayant.jha2,
Seems the ODATA service is expecting an array instead of single element.
You can convert it to array using a groovy script.
hope this helps !
thanks and regards,
Praveen T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.