Multilevel Mapper

This mapper is used to remap values from multiple levels of multiple sources into one output body. It can combine calculated values with values extracted from the body and headers, including lists at several levels. Output mapping must always be unambiguous.

Map rules have the following syntax:

  • The dot char '.' separates individual mapping parts.

  • Square brackets '[]' in the end of a mapping part mean that the input contains a list at the given level.

  • You may use [] as the first mapping item to refer to an input list.

  • You need to respect the number of arrays in mapping. E.g. you cannot have mapping data[].sub[].item → myData[].myItem

  • You may use array index notation to access fields in an array. The previous rule does not apply here. Example: toDescription.result[0].Product → label

Using Aggregation Mode

The difference between aggregate=true (default) and aggregate=false is described in the following table:

Mapper Mode

aggregate = true

aggregate = false

Mapper Mode

aggregate = true

aggregate = false

Input data

[ { "resultPrice": "10.5", "sku": "P14", "currency": "CZK" }, { "resultPrice": "11.5", "sku": "P15", "currency": "JPY" } ]

Headers

{ "priceListId": "5", "messageId": "M5" }

Mapper

<multilevelMapper> <header in="priceListId" out="plId"/> <header in="messageId" out="msg"/> <body in="data[].resultPrice" out="priceSpecificationList[].amount"/> <body in="data[].sku" out="priceSpecificationList[].productId"/> <body in="data[].currency" out="priceSpecificationList[].currency"/> </multilevelMapper>

Result

Comment

When the aggregation mode is used, the mapper is applied on input data only once, regardless if it is an array or tree structure.

The mapper definition then uses square brackets [] to map items into a single element in the final JSON tree.

When the aggregation mode is not used, the mapper is applied n times for the length of the input data n. The mapper then duplicates the constants (e.g. from header) into every element.

Notice that square brackets are not used in the mapper definition. The reason is that it is assumed that the input structure is a list, so you have the 1st level access to its properties.

Preferred use

You want to have the output as a single object without repetitions.

You want to map the input tree/list in a uniform way.

Using Deflate Option

The Deflate option is useful when you need to have a result as a list. This is useful e.g. in combination with pfx-rest:laoddata whose input must be an array.

 

deflate=false (default)

deflate=true

 

deflate=false (default)

deflate=true

Mapper

Data

Result

  • Notice that the result is an object in which the field pl is an array.

  • Notice that the result is a deflated field pl – array.

Examples

This example maps the value with the productId key from the list of items received in the body to the item of the plItems list and stores the value under the prId key.

 

This example maps the value with the productId key from the list of items received in the map entry priceList containing a list to the item of the plItems list and stores the value under the prId key.

 

This example shows nested lists mapping.

 

This example maps the header value priceListName to plName – this can be combined with the values from other sources.

 

This example evaluates a simple expression and stores the value to the output as a map with the bodyMetadata key and the value bodyLength with the calculated value.

 

This example maps the exact string 'property value' to the subItem entry contained in the property1 map.

 

This example maps the calculated Groovy expression to the structure like one={two={three=2019-11-16}}.

 

This example maps a list of values from input body with rounding.

 

This example shows how to access an item at index in an array.

Complex Mapping Examples

The mapping rules below show how to map the header, body, constant property and calculated fields into one combined output body.

 

 

 

 

 

 

 

 

 

 

 

→

 

IntegrationManager version 5.8.0