Integration mappers
Integration mappers
- A root type
- Both the expected runtime input to this mapper and the base type of the symbol
available to
pathandpredicateexpressions. - A schema definition
- The JSON Schema definition whose output this mapper is producing. The schema definition is resolved in the context of the root schema name for the mapping file.
- A set of properties
- Definitions for obtaining data for each property in a referenced schema definition. A mapper is not technically required to specify every property on the referenced schema definition. However, a warning will be issued if there are properties on the schema definition that are not being mapped.
Mapping properties
properties
are assumed to be the names of the JSON schema definition properties. Effectively, the
integration mapper is defining the output directly in terms of the schema. The integration
mapper is then specifying how to get the value for each property that can appear in the output.- path
-
Each mapping property must specify a
pathexpression. This expression is a Gosu expression that evaluates to the value that must be used as the output of that schema property. Thepathexpression has a single symbol available to it. The single symbol has a type equal to the root type of the mapper. The single symbol also has a name equal to the relative name of the type. For example, suppose that the root type for a mapper is entity.Contact. Thepathexpressions on the mapper properties will have a single symbol named Contact with a type of entity.Contact. The path expression must evaluate to something appropriate for the referenced schema property:- If the schema property is a scalar property, the path expression must evaluate
to a Java Input Type listed in JSON data types and formats. The evaluation is based on the type/format/x-gw-type of
the schema property. For example, if the schema type is
stringand the format isdate-time, thepathexpression must evaluate to something assignable to java.util.Date. - If the schema property is an array of scalars, the path expression must evaluate to an Iterable or array. The elements of the Iterable or array can be inputs to the data conversion for the type of the schema property items.
- If the schema property is an object property, then the
mapperproperty must be specified. In addition, the return type of the path expression must be assignable to the root type of the referenced mapper. For example, if the referenced mapper is#/mappers/Addressand the Address mapper has a root type of entity.Address, the path expression must evaluate to an entity.Address or a subtype. - If the schema property is an object array property, then the
mapperproperty must be specified. In addition, thepathexpression must evaluate to an Iterable or array whose elements can be assigned to the root type of the referenced mapper.
stringwith no format or isx-gw-type, the Gosu path expression must evaluate to a java.lang.String. This evaluation must be with no implicit invocation of toString or any similar method.The path expression can be an arbitrary Gosu expression. The expression is not required to be a simple property path. The expression could be a method call, a static method call, or another complex Gosu expression.
- If the schema property is a scalar property, the path expression must evaluate
to a Java Input Type listed in JSON data types and formats. The evaluation is based on the type/format/x-gw-type of
the schema property. For example, if the schema type is
- predicate
- The
predicateproperty is an optionalbooleanorBooleanpredicate that will be evaluated before thepathexpression is evaluated. Thepredicateproperty can also return a java.lang.Boolean type. However, the property cannot evaluate tonullat runtime. If thepredicateexpression evaluates tofalse, the path expression will never be evaluated and the property will be treated as having anullvalue. Thepredicateexpression can be used to guard the evaluation of thepathexpression. This guarding can be useful if the output schema flattens subtype columns onto a single object. For example, suppose that the output schema for Contact defines propertiesfirstNameandlastName. In this case, thepredicateexpression might beContact typeis Person, and thepathexpression could be(Contact as Person).FirstName. Using thepredicateexpression in this way allows thepathexpression to downcast directly instead of using a more awkward ternary expression. - mapper
-
The
mapperproperty defines the mapper to use when theschemaproperty is an object or array of objects. Mapper references use a similar syntax as schema references. They must be of the form#/mappers/<name>when the referenced mapper is defined in the same mapping. They must be of the form <alias>#/mappers/<name> when the mapper is imported as <alias>. The referenced mapper must have aschemaDefinitionproperty that matches the$refon theschemaproperty. For example, suppose that the Contact JSON schema definition has aprimaryAddressschema property with a$refof #/definitions/Address. In this case, theprimaryAddressproperty on the Contact integration mapper must have amapperreference where theschemaDefinitionis Address. See Integration mapping examples for an example of how the structure of integration mapping properties and mapper references mimic the structure of JSON schema properties and definition references.
See also
