on 2021 Oct 25 4:32 PM
I am receiving a JSON token that is not using standard file names. Instead of "issued": I'm receiving ".issued": and ".expires":. The standard JSON to XML converter was working but it starting erroring over the weekend. I've tried to use a groovy script prior to the standard conversion to rename ".issued" to "issued" and ".expires" to "expires", but when it runs it is dropping the double quote" in front of the tag for "expires_in". This is resulting in the error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 278 path $.token_type. The script that I'm using is:
def msgBodyOriginal = message.getBody(java.lang.String) as String;
def msgBodyModified = msgBodyOriginal.replaceAll(".issued","issued");
def msgBodyModified2 = msgBodyModified.replaceAll(".expires", "expires");
message.setBody(msgBodyModified2);
return message;
}
I've tried just replacing all occurrances of "." but it results in an empty body. Any and all help is appreciated!!
Request clarification before answering.
Hi Beverely
As apalagin points out (and you should accept their answer), this is because of the updated behaviour of the JSON to XML converter. .issued and .expires cannot be converted to XML element names (since they must begin with a letter or a number), and therefore the conversion fails.
What you need to do, is either process the JSON in a script, or use a script to update the offending names before the conversion. Your script is almost correct. The first parameter of the replaceAll method is a regular expression, and in a regular expression, the dot translates to any character whatsoever. If you quote it, your script will work. So something like this:
def body = message.getBody(String)
def newBody = body.replaceAll("\\.issued", "issued").replaceAll("\\.expires", "expires")
message.setBody(newBody)
return messageRegards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Beverly
Potentially, this could be because of the CPI upgrade which included changes to the JSON to XML converter, see details here.
Cheers
Alexey
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are there any options other than asking SAP to reverse this enhancement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 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.