Discussion
Pegasystems Inc.
US
Last activity: 24 Oct 2022 17:29 EDT
How do you get the RAW JSON from a clipboard conversion?
The client needs to do some specific logging and we are having to use the function pxConvertPageToString to get the JSON message. However Pega includes pxObjClass specifics in the produced JSON text as shown below. Is there a way to get the RAW JSON without the Pega information being included?
"{
"pxObjClass":"DB-FW-CAR-Int-CRREV1-CalculateClientRisk_Request"
,"body_POST":{
"pxObjClass":"DB-FW-CAR-Int-CRREV1-CalculateClientRisk_Body_POST"
,"clientRiskRatingRequest":[
{
"pxObjClass":"DB-FW-CAR-Int-CRREV1-ClientRiskRatingRequest"
,"clientDetails":{
"pxObjClass":"DB-FW-CAR-Int-CRREV1-ClientDetails"
,"recordID":"1"
,"riskRatingType":"LOCAL"
}
,"entityRiskType":{
"pxObjClass":"DB-FW-CAR-Int-CRREV1-EntityRiskType"
,"typeKYCLegalEntity":"Error"
}
,"industryRiskType":{
"codeType":"NACE"
,"pxObjClass":"DB-FW-CAR-Int-CRREV1-IndustryRiskType"
}
,"productRiskType":[
{
"productName":"Adoption Only"
,"pxObjClass":"DB-FW-CAR-Int-CRREV1-ProductRiskType"
}
]
}
]
,"header":{
"callerSystem":"59248-1"
,"pxObjClass":"DB-FW-CAR-Int-CRREV1-Header"
,"requestID":"dbCAR-16113834"
,"requestTimeStamp":"2017-03-01 19:11:53+02:00"
}
}
}
"
***Updated by moderator: Lochan to add enhancement request ID under Related Support Case Number field***
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
US
Hello,
May i know where exactly you want this functionality, i mean is it in Connect-REST/Service-REST?
If so, Map from as JSON and Map from key as your response Page property on the Connect/Service REST rule.
Else kindly let us know your use case to understand your scenario of usage.
Regards
Mahesh
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
US
We are letting the rest connector perform the conversion itself from the clipboard when calling the actual service. However they have a hard requirement to log the raw JSON request and response. Response is simple enough as it comes back in the true raw format. However we have to use a conversion function to capture the request.
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
GB
I stole the following answer from an internal forum: where a similar question was asked:
You might be able to adapt this for your use case as well:
// generate json from this template
com.pega.dsm.dnode.util.ClipboardPageJsonConverter converter = new com.pega.dsm.dnode.util.ClipboardPageJsonConverter(false);
converter.setPrettyPrint(true);
java.nio.ByteBuffer json = converter.asJson(sourcePage);
String jsonString = new String(json.array());
// remove pxObjClass
jsonString = jsonString.replaceAll("\"pxObjClass\"\\s*?:\\s*?\".*?\",?\\s+", "");
return jsonString;
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
US
Is this really the best we have? It seems that at some point they are injecting all the pxObjClass entries. Surely I would think they have a way to generate the JSON without the injections.
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
GB
I checked the OOTB Pega Engine class Javadocs as well: found this call:
ClipboardPage.getJSON( boolean aEncode )
Unfortunately this also returns back the *full* set of properties in the page (including the 'pxObjClass' property and other 'px' props).
There might be another way: but I don't know it I'm afraid. (Aside from the 'subtractive' approach I gave above).
Maybe somebody else does ?
I have logged a 'Feedback' / 'Enhancement' Request here: (this isn't a guarantee of a fix of course; but it does allow our SMEs to review the viability of such a change). I have included the ID, title and text of the ENH below; and I have referenced this Post in the ENH itself.
FDBK-18584: ClipboardPage.getJSON : flag to eliminate px, py, pz props.
It seems that at least one customer is after a way of getting a JSON payload, based on a PRPC Clipboard, which *excludes* the 'pxObjClass' property.
I have therefore suggested a catch-all ENH here: a variation of the Method 'getJSON' that allows you to specify a regex to filter out matching properties.
So for instance you could specify something like: (And I mean 'something like' here: I haven't double-checked that Regex - it looks *about* right to me).
^px.$*|^py.$*|^pz.$*
To drop / filter-out any 'px', 'py' or 'pz' properties.
I checked the OOTB Pega Engine class Javadocs as well: found this call:
ClipboardPage.getJSON( boolean aEncode )
Unfortunately this also returns back the *full* set of properties in the page (including the 'pxObjClass' property and other 'px' props).
There might be another way: but I don't know it I'm afraid. (Aside from the 'subtractive' approach I gave above).
Maybe somebody else does ?
I have logged a 'Feedback' / 'Enhancement' Request here: (this isn't a guarantee of a fix of course; but it does allow our SMEs to review the viability of such a change). I have included the ID, title and text of the ENH below; and I have referenced this Post in the ENH itself.
FDBK-18584: ClipboardPage.getJSON : flag to eliminate px, py, pz props.
It seems that at least one customer is after a way of getting a JSON payload, based on a PRPC Clipboard, which *excludes* the 'pxObjClass' property.
I have therefore suggested a catch-all ENH here: a variation of the Method 'getJSON' that allows you to specify a regex to filter out matching properties.
So for instance you could specify something like: (And I mean 'something like' here: I haven't double-checked that Regex - it looks *about* right to me).
^px.$*|^py.$*|^pz.$*
To drop / filter-out any 'px', 'py' or 'pz' properties.
Or you to JUST drop more specific properties; say 'pxObjClass':
^pxObjClass$
Or maybe we shouldn't 'drop', instead we 'match' for *wanted* properties.
Or offer both types.
Then we could offer a 'convenience' pre-built REGEX that checks for system properties etc; and provide that as a 'constant' for the function.
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
US
Thanks, I have been through all the JSON methods I could find. It seems for all the exposed ones I can find they all add the pxObjClass stuff. What is weird is that when the REST connector runs there is a property on the clipboard that is raw (begins with a prefix of "Request Method =") except for a prefix. Shouldn't be this difficult to just get the raw JSON. Thanks for getting the ER in.
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
US
Basically after engaging engineering there is a way to get the RAW JSON from a clipboard page. Below is the code you have to use to create a function for it.
PublicAPI tools = pega_rules_utilities.getPublicAPI();
ServiceUtils utils = tools.getServiceUtils();
ParameterPage paramPage = tools.getParameterPage();
ClipboardProperty mappingConfprop = tools.createPage("Rule-Connect-REST", "").getProperty("pyPOSTRequestDataList");
ClipboardPage mappingConfPage = mappingConfprop.getPageValue(1);
mappingConfPage.putString("pyMapFrom", "JSON");
mappingConfPage.putString("pyMapFromKey", sourcePropertyRefAsStr);
mappingConfPage.putString("pyDataType", "String");
mappingConfPage.putString("pyParameterName", "OutboundData");
java.util.Map dataMap = new java.util.HashMap(3);
utils.mapOutboundData(mappingConfprop, dataMap, paramPage, sourcePage);
return (String)dataMap.get("OutboundData");
Updated: 27 Apr 2022 16:38 EDT
Pegasystems Inc.
US
I was able to get the expected results by slightly modifying SIMMR-1's code as follows:
PublicAPI tools = pega_rules_utilities.getPublicAPI();
ServiceUtils utils = tools.getServiceUtils();
ParameterPage paramPage = tools.getParameterPage();
ClipboardProperty mappingConfprop = tools.createPage("Rule-Connect-REST", "").getProperty("pyPOSTRequestDataList");
ClipboardPage mappingConfPage = mappingConfprop.getPageValue(1);
mappingConfPage.putString("pyMapFrom", "JSON");
mappingConfPage.putString("pyMapFromKey", sourcePropertyRefAsStr);
mappingConfPage.putString("pyDataType", "String");
mappingConfPage.putString("pyParameterName", "OutboundData");
java.util.Map dataMap = new java.util.HashMap(3);
utils.mapOutboundData(mappingConfprop, dataMap, paramPage, mappingConfPage);
return (String)dataMap.get("OutboundData");
When you write your function it must accept the sourcePropertyRefAsStr parameter as a String. I was only successful getting a valid response when I pass the full page context. I named my function getJSON so it's called like: @getJSON("OFFER.getOffer")
Hope this helps.
-
Helen Hanna
Updated: 27 Apr 2022 16:38 EDT
Cognizant Technology Solutions Pvt Ltd
US
This is very helpful. Thank you !!
Updated: 27 Apr 2022 16:38 EDT
Vodafone Intelligent solutions
IN
@heitk I used your code and able to get the raw json , but only the values not with the field names.
Example : If I pass value "{"name":"Amit", "age":"18"}"
Result I am getting is = {"Amit",18}
Is there a way to get field names also?
Updated: 27 Apr 2022 16:38 EDT
Coforge
IN
Hi,
Can you please explain high level about the below function.
utils.mapOutboundData(mappingConfprop, dataMap, paramPage, sourcePage);
how it is excluding pega properties.
Updated: 27 Apr 2022 16:38 EDT
EY
IN
To convert raw Json now in latest version it is simplified.Create data transform with Json format, once created use auto mapping which converts clipboard page to json and also have option to exclude Properties e.g. objclass whichever not required in the output json.output of the json is stored in out parameter of datatransform.
Knowledge Expert
FR
@SIMMR-1 you can keep Raw JSON response by passing Param.storeRawMessage=true to Connect-REST. More info can be found there: https://rule.tips/integration/rest/2022/02/16/raw-message-connect-rest.html