What is the best way to convert a clipboard page and/or xml to json in pega 7.1.5? I imagine there is a java method or pega function that is invoked for REST service functionality... my needs are not REST-specific, but I should be able to use the same assets.
**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.
The ClipboardPage java API has JSON and XML conversion methods - adoptJSONObject, adoptJSONArray, and adoptXMLForm for populating a clipboard page with JSON/XML data, getJSON and getXML for converting the contents of a clipboard page to an JSON/XML string value.
// generate json from this template
com.pega.dsm.dnode.util.ClipboardPageJsonConverter converter = new com.pega.dsm.dnode.util.ClipboardPageJsonConverter(false);
java.nio.ByteBuffer json = converter.asJson(sourcePage);
String jsonString = new String(json.array());
// remove pxObjClass
jsonString = jsonString.replaceAll("\"pxObjClass\"\\s*?:\\s*?\".*?\",?\\s+", "");
The class/package names may need to altered - depending on your version of PRPC (The first example comes from PRPC72 for instance).
The JSON handling/conversions in upcoming versions of PRPC will be improved to provide an easier way to perform JSON<->Property mappings; but unfortunately (as far as I know) - you are stuck with having to 'post-process' the JSON as shown above.
I have simmilar requirement to send JsonObject in Rest Header, I have used the below code to convert Clipboard object to JSON but it gives me a JSON object with pxObjClass. I tried the above approach mentioned but no luck. Please help me