Mappings

interface Mappings

The Mappings interface is used to build up key/destination mappings that are applied on top of the full Dispatch payload before it is sent to a given Dispatcher.

Keys that are not mapped to are kept as they are, while a mapped destination replaces any existing value. The only exception is the root Dispatch.Keys.COMMAND_NAME key, where mapped values (constants or variables) are appended to any value already there, flattening lists one level, so that multiple commands can be collected (e.g. an existing ["a"] with a mapped ["b", ["c"]] gives ["a", "b", ["c"]]). If a parent along the destination path holds a value of a different type (e.g. a string where an object is needed, or an object where a list is needed), it is replaced. Sources are always read from the original payload, so mappings don't chain. Derived values should be computed with a dispatcher-scoped transformation, which runs before mappings.

Use the multiple mapFrom methods to supply the required source "key" and "destination" key, as well as any optional "path" entries required to access keys in nested object.

Using the following payload DataObject as an example (shown as JSON)

{
"source" : "value",
"path": {
"to" : {
"source": "nested value"
}
}
}

Simple usage for keys in the top level DataObject would look like so:

mapFrom("source", "destination")

More complex versions requiring accessing keys that exist in nested objects would look like so:

mapFrom(JsonPath["path"]["to"]["source"], JsonPath["path"]["to"]["destination"])

The mapFrom method returns a VariableOptions that allows for setting optional properties relevant to a mapping.

See also

Inheritors

Types

Link copied to clipboard

The CommandOptions allows for configuring optional properties relevant only when mapping commands for Remote Command Dispatchers.

Link copied to clipboard
object Companion
Link copied to clipboard
interface ConstantOptions

The ConstantOptions allows for configuring optional properties relevant only when mapping constant values to the destination.

Link copied to clipboard
interface VariableOptions

The VariableOptions allows for configuring optional properties relevant only when mapping values from the source payload.

Functions

Link copied to clipboard
abstract fun build(): List<MappingOperation>

Builds and returns the list of mapping TransformationOperations that have been configured.

Link copied to clipboard

Adds a mapping where the value to map is given by the constant name and will be mapped to a fixed destination of Dispatch.Keys.COMMAND_NAME.

Link copied to clipboard
abstract fun mapConstant(value: DataItem, destination: JsonObjectPath): Mappings.ConstantOptions

Adds a mapping where the value to map is given by the constant value and will be mapped to the given destination located/stored at some configured level of nesting as defined by the JsonObjectPath.

abstract fun mapConstant(value: DataItem, destination: String): Mappings.ConstantOptions

Adds a mapping where the value to map is given by the constant value and will be mapped to the given destination

Link copied to clipboard

Adds a mapping where both the path and destination can be located/stored at some configured level of nesting as defined by the JsonObjectPath for each input.

abstract fun mapFrom(path: JsonObjectPath, destination: String): Mappings.VariableOptions

Adds a mapping where the destination is to be in the top level of the mapped payload, but the source key is defined at some nested object/list as defined by path.

abstract fun mapFrom(key: String, destination: JsonObjectPath): Mappings.VariableOptions

Adds a mapping where the key is to be found in the top level of the input payload, but the destination key is to be defined at some nested object/list as defined by destination.

abstract fun mapFrom(key: String, destination: String): Mappings.VariableOptions

Adds a mapping where the key and destination are in the top level of the payload.

Link copied to clipboard
open fun path(root: String): JsonObjectPath

Utility method to start creating JsonObjectPaths. This method is shorthand for JsonPath.root