Question

PEGA 7.1.9 -- How to remove pxObjClass from Json Response

I have Service-Rest returning response in JSON format

I am using pxConvertPageToString fuction to prepare response in JSON but source page have pxObjClass property same is getting included in response.

I tried Property-Remove to remove pxObjClass from source page, getting below error,

pxObjClass is unmodifiable. Calling method: com.pega.pegarules.data.internal.clipboard.ClipboardPropertyImpl.setValue(Object) Details: property is reserved

Correct Answer
October 9, 2018 - 6:30am

Got one way which is set Map from JSON directly (Enter the reference to a Page or Page List property) in response tab which just generate response in json without having pxobjclass in it.

 

Comments

Keep up to date on this post and subscribe to comments

October 9, 2018 - 5:56am

@Lochan_DV -- Please help if you have any solution

October 9, 2018 - 6:30am

Got one way which is set Map from JSON directly (Enter the reference to a Page or Page List property) in response tab which just generate response in json without having pxobjclass in it.

 

October 9, 2018 - 7:19am

HI,

Can you try below code in java step.

String pageContent = resp;

ClipboardPage tempPage = null;

try{

  tempPage = tools.createPage("Your Response Class","ResponsePage");
  

  tempPage.adoptJSONObject(pageContent);

} catch(InvalidStreamError e){

  oLog.error("ReloadSection:Invalid JSON Stream for data page params : "+e.getMessage());

} catch(Exception e){

  oLog.error("ReloadSection:Expection : "+e.getMessage());

}

String streamToShow = tempPage.getJSON(false);

December 10, 2018 - 7:03am

Hi,

If you are using the pxConvertPageToString  function then pxObjClass will be added by default and you cannot use the Property-Remove.

To remove this I wrote a java step and included the Gson API call using the com.google.gson for which you need to include the gson-2.3.1.jar

Here is the code

String jsonString = "{ \"pxObjClass\":\"Employee-Class\"," +
                "   \"name\":\"kamal\"}

com.google.gson.JsonParser parser = new com.google.gson.JsonParser();
com.google.gson.JsonObject jsonObject = parser.parse(jsonString).getAsJsonObject();
jsonObject.remove("pxObjClass");
jsonObject.toString();

Also to include this jar into PEGA . We need to follow the below steps.

1) If your PEGA is running on WEb-logic , keep the jar in the lib folder

2)Mention the jar name in Records > SysAdmin > Dynamic System Settings > compiler/defaultPaths

as /opt/weblogic/domains/pega_domain/lib/gson-2.3.1.jar 

Note that if the server us running on LINUX and there  multiple jar files in compiler/defaultPaths the new jar should be seperated by : instead of ;
if it is windows machine then use the ; instead of :

3)Restart the server.

Now the code should work and return the json string excluding the pxObjClass property

Pega
October 9, 2019 - 11:52am

Hi ,

You can use the pxConvertPageToString -@(Pega-RULES:Page).pxConvertPageToString(tools,clipboardpage,"json") ,which will give you the json string with pxobjclass that you can get rid of using the below regularexpressions

JSONstring=@(Pega-RULES:Page).pxConvertPageToString(tools,clipboardpage,"json")

JSONstring=@pxReplaceAllViaRegex(JSONstring,",.*?\"pxObjClass\":\"\"","")

JSONstring=@pxReplaceAllViaRegex(JSONstring,"\"pxObjClass.*?\n,","")

JSONstring=@pxReplaceAllViaRegex(JSONstring,"\"pxObjClass.*?\n","")