Sorting order on Page as XML

We have an external system which expects the JSON input values in a specific order. However when we set the properties on the page and pass it to the connector as a request , the order of the properties are changed,

eg: Customer { "ID":"C-123","FirstName": "test"} - Expected

Customer { "FirstName": "test","ID":"C-123"} - Actual

When i extracted the page as an XML is was showing the same order as the one used in the JSON. How does pega determine the order and how can we override it?


Keep up to date on this post and subscribe to comments

July 9, 2019 - 1:32am


I suggest you look at the Java in the Activity Invoke. The bad news is that the ServiceUtils public API interface converts the clipboard values with:

     utils.mapOutboundData(resourceParams, (Map) resourceParamVals, params, (ClipboardPage) dataPage );

Since plain Maps aren't normally ordered, you'll need to override Invoke and add a little Java. See step 5 and the line

     java.util.HashMap resourceParamVals = new java.util.HashMap();

My suggestion would be to change HashMap to a TreeMap and feed its constructor a Comparator you instantiated on the preceding line with an anonymous implementation that sorts your parameters in the order desired. Of course you need context-specific Comparators, so maybe a circumstanced or parameterized activity responsible for just creating the Comparator would be best. Invoke calls it to receive the Comparator before the current step 5, it gets set it to a local Object variable before step 5, and step 5's only change is:

     java.util.HashMap resourceParamVals = new java.util.TreeMap(comparator);

It should work!