Marshalling and Unmarshalling in the GLU Engine
Marshalling (writing) and unmarshalling (reading) are processes used on both the client/sender side (upstream) and the server/receiver side (downstream) of the GLU engine.
Unmarshalling (Reading)
When a request enters the GLU engine, it undergoes unmarshalling—the process of transforming the incoming data into the GLU Object Model (typically in JSON format). This process applies to both inbound requests and outbound responses. Unmarshalling can involve:
• Saving the entire array as-is
• Searching for and extracting specific values
• Storing only part of the array’s contents
Note: For details on how to include arrays in responses, refer to the Response Manager documentation and response template guidelines.
Array Unmarshalling Principles
1. We always use the JSON payload (incoming or response) for our structure when unmarshalling.
2. The array structure in the source must match that of the target parameter (i.e., an array cannot be stored in a single parameter).
3. When unmarshalling with a condition:
• If only one array index matches the condition and both the condition and attribute are on the same level in the JSON structure, then you can save that value into a single parameter.
• Otherwise, the source and target structures must match, meaning the array structure must be preserved.
Unmarshalling Array configuration
Attribute name: This is the name of the specific attribute whose value you want to retrieve from the response or request.
Object / Collection Path: Regardless of the original content type of the request or response, it is always transformed into a JSON structure (you can view this transformation in the DEBUG logs). The Object/Collection Path represents the location of the attribute within this JSON structure. If the attribute is inside an array, this is indicated using [] to show the array elements in the path..
Condition: If you only want to retrieve specific records from a response, you can apply a condition to filter the data. This allows you to extract only the values that meet the specified criteria.
Reading Unmarshalling Logs
Understanding Logs for Value Retrieval
Reading the logs can be very useful for identifying:
1. The value that has been retrieved.
2. The source—where the value is being pulled from.
3. The target—where the value is being saved, including the class or array details.
If you encounter an error such as:
“Error Saving Parameter [value] in GLU OBJECT Due >> must be a class or class from array!”
This indicates that the source and target structures do not match. In most cases, the issue arises because the value should be saved into an array, but is instead being treated as a non-array structure. Ensure that the parameter is correctly saved into an array if needed.
Un-marshalling like for like arrays
If my response from a third party looks like this:
For each parameter in the array, the unmarshalling and parameter properties would be defined as follows:
• Unmarshalling: In this step, the object/collection path is specified to locate the array (e.g., “result”), and the attribute inside each element of the array (e.g., accountID, amount, or balanceType) that needs to be saved into a parameter is identified.
• Properties: In this section, the parameter name is defined, along with the reference to the object (e.g., the “result” array) from which the parameter (e.g., accountID, amount) will be extracted and saved.
Unmarshalling from unnamed arrays
If my response from a third party looked like this:
You can follow the above steps and replace the name of the array with empty square brackets – as shown in the ‘Object / Collection Path’ field below:
Marshalling to unnamed arrays
See example below; the array is nested within an object under the key “array”. This means the array is not at the root level but is a property of an object.
• Inside the “array”, each object only has one property (attribute) with a corresponding value.
If you want to marshal an array and save it as an unnamed array, you can use the ‘Store as Object’ option. This way, the array will be stored as an object (unnamed array). Here’s an example:
To:
Unmarshalling/Marshalling array of values
If the response form third party looks like this:
You can follow the above steps, but leave the attributes fields empty to unmarshall or to marshall.
Unmarshalling using a condition
SCENARIO 1 – Source Array is a FLAT ARRAY OF OBJECTS :
If my response from a third party looked like this:
If you want to retrieve the balance for accountID = 0, you can add a condition to your unmarshalling configuration. This condition will check each record in the array and retrieve the value where the condition is met. Since you expect only one record in the result set to satisfy this condition, you can store the retrieved value in a single parameter.
However, if multiple records meet the condition, you can still store the values in the parameter, but you’ll need to include the object (array) name in the property object field to correctly reference the array in your configuration.
SCENARIO 2 – Source Array is a NESTED ARRAY OF OBJECTS :
If my response from a third party looked like this – you can see that the tx Array is NOT a flat set of objects.
If I want to get the details from the tx array where the it is for the Tariff:
Unmarshalling with a condition where the attribute and condition sit at the SAME level in the array:
Unmarshalling path: The path from the top of the json payload defining the position of where the attribute is sitting: e.g. creditVendResp.transactions.tx[]
Attribute name: accNo
Condition: accDesc==’Tariff Charge‘
Unmarshalling with a condition where the attribute and condition DO NOT sit at the same level in the array:
Unmarshalling path: The path from the top of the json payload defining the position of where the attribute is sitting: e.g. Envelope.Body.creditVendResp.creditVendReceipt.transactions.tx[].amt
Attribute name: value
Condition: tx.accDesc==’Tariff Charge’
This tells us that the unmarshalling path and attribute always go down to the level where the attribute sites. If that level differs to where the condition must be executed, you need to update the condition to understand where in the unmarshalling path to find that condition attribute.
Unmarshalling only part of the array contents
In the above example, if you only want to unmarshal the array and save the accountID and amount fields into an array, then you only need to add those two parameters in the response parameters with the correct configuration included for unmarshalling. This will create the new accounts object without the balanceType parameter.
Consolidating amounts in an array
If I received an array with multiple records for one unique identifier (e.g. accountID) and you wanted to return a consolidated / overall balance for each accountID you could use the following function. This function could be executed on a response handler once the array has been unmarshalled into the engine. It is available in GLU Functions & Formulas
If you receive an array with multiple records for one unique identifier (e.g., accountID) and you want to return a consolidated/overall balance for each accountID, you can use the following function, available in GLU Functions & Formulas:
CONSOLIDATE(${accounts},accountID,amount) |
- parameter 1 (arrayName): the array name where you have unmarshalled your data
- parameter 2 (paramNameConsolidateBy): consolidate to this identifier
- parameter 3 (paramNameToConsolidate): the parameter which you want to add up
This function would work for an incoming array structured like this:
The output would look like this:
1. Set a Derived Parameter:
Start by configuring a derived parameter that will hold the value you intend to compute or override later.
2. Unmarshal Required Parameters:
In the response parameters, unmarshal the necessary values into an accounts array. This will collect all relevant parameters in a structured format, ready for further processing.
3. Use a ‘None’ Handler in the Response Handler:
In your response handler, apply a “none” handler, which effectively prevents any additional transformations. This step allows you to override the derived parameter directly with the function you’ve specified.
4. Override the Derived Parameter:
Finally, use the function in your configuration to set or compute the value of the derived parameter, replacing its initial placeholder.
See the example below:
Unmarshalling a specific position in an array
You can access a specific position in an array by using a shortcut:
In the accounts array, to retrieve the value of the accountID from the first record, you can use the following expression:
${accounts[0].accountID} |
accounts
: Refers to the array name.[0]
: Indicates the position in the array (in this case, the first record).accountID
: Specifies the value in the first record that you want to retrieve.
Finding a value of a specific position/attribute in an array
If you have unmarshalled successfully into an array – and you want to get one of the values out of the array.
You can create a derived parameter which specifies the detail of what you want to access: ${arrayname[index].attributeName}. This will print the value and make it accessible in the derived parameter.
e.g. ${filtered[0].ti} – this will take the ti value out of the filtered array from index position 0.