on 2020 Mar 20 7:52 PM
I'm working on an implementation where the receiver is requesting a JSON file format. I'm using integration mapping to create an XML that matches the JSON format. I'm then executing standard XML to JSON conversion followed by a groovy script to remove the "element" entries from each object array. My final step is that if an object array contains an empty element, the result should be an empty object array that looks like: "TestQualitativeMeasurement":[].
If I create the element regardless of data, convert XML to JSON, and execute my script, my results look like "TestQualitativeMeasurement":[""] (Receiver is not accepting this as an empty object)
I've tried not mapping the element if there is no data but this results in the object array end up looking like "TestQualitativeMeasurement":"" and is missing the [] object qualifers required.
Would anyone be able to advise me on how to accomplish this? I believe that I should be able to do this within my groovy script but I haven't found the right combination.
Thank you
Request clarification before answering.
Hi Beverly,
since JSON is just a "String", you could simply run a search-replace script after your JSON conversion.
import com.sap.gateway.ip.core.customdev.util.Message
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String
body = body.replace("[\"\"]","[]")
message.setBody(body)
return message
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. That worked perfectly and as I try to learn Groovy scripting, I learned about escape characters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.