Field Value Mappers

When setting values on the target message from the source message, it might be necessary to perform type conversion. Multiple included FieldValueMapper types can perform this conversion (for example, converting a string to an integer).

By default, the Dynamic Message Mapper checks if an appropriate FieldValueMapper already exists that is capable of converting from the defined type for the source message field to the defined type for the target message field.

If a different conversion is required, you can define your own FieldValueMapper. An example of a custom Radio Access Technology (RAT) type FieldValueMapper appears in the following section.

This example shows definition of a custom field value mapper for RAT:

customFieldValueMappers:
  - name: "rattype"
    targetType: "long"
    map:
      - NR: 1
      - EUTRA: 2
      - WLAN: 3
      - VIRTUAL: 4

Any number of FieldValueMappers can be defined under customFieldValueMappers. Each must have a name for referencing it in the field mapping. Optionally, a targetType (string, by default) can be used to specify the value type to produce.

The example uses a map-based FieldValueMapper, which uses the value of the source message field to look up which value to use in the target message field. If the value does not exist in the map, a null value is returned by default. If you need the original value, set useOriginalValue attribute to true.

Note: In the example, using the useOriginalValue attribute would result in a NumberFormatException, because the string value of RAT type cannot be converted to a long.

Regular Expression-Based Field Value Mapper

Like the map-based field value mapper, you can use the regexmap property to use regular expressions for the keys mapping to values. The regular expressions are checked in order and the first successful match is used.

customFieldValueMappers:
 - name: "httpStatusCodeMapper"
   regexmap:
    - "^1[0-9]{2}$": "INFO"
    - "^2[0-9]{2}$": "SUCCESS"
    - "^3[0-9]{2}$": "REDIRECT" 
    - "^4[0-9]{2}$": "CLIENT_ERROR" 
    - "^5[0-9]{2}$": "SERVER_ERROR"
    - "^[6-9][0-9]{2}$": "UNKNOWN"

Java Custom Field Value Mapper

You can also specify a className property that has the fully qualified class name of a FieldValueMapper implementation (which must be in the classpath). Any other defined properties are treated as attributes of this implementation and must have corresponding setters, which take a single string attribute.

This example shows configuration of a custom field value mapper:

customFieldValueMappers:
  - name: "rattype"
    className: "com.example.mapping.MyCustomFieldValueMapper"
    prefix: "123"

This example shows the custom field value mapper implementation:

public class MyCustomFieldValueMapper extends FieldValueMapper<String, String> {
 
    private String m_prefix;
 
    public void setPrefix(String prefix)
    {
        m_prefix = prefix;
    }
     
    @Override
    public String map(final String source)
    {
        return m_prefix + source;
    }
}

Groovy Custom Field Value Mapper

Like className, you can also use the groovyFile property to specify the path (relative to the mapping configuration file) to a Groovy file containing the implementation.

This example shows configuration of a custom field value mapper using the groovyFile property:

customFieldValueMappers:
  - name: "rattype"
    groovyFile: "MyCustomFieldValueMapper.groovy"
    prefix: "ABC"

In that example, the groovyFile property specifies a file with this implementation:

class MyCustomFieldValueMapper extends FieldValueMapper<String, String> {
    def prefix;

    void setPrefix(String prefix)
    {
        this.prefix = prefix;
    }

    @Override
    String map(final String source)
    {
        return prefix + source;
    }
}

MATRIXX SubType Field Value Mappers

If a field with a subtype definition is found when loading the MATRIXX Data Container (MDC) field metadata, two new field value mappers are created and registered. These are used for mapping string values to and from the numeric value and they have the names string.nameOfSubType and nameOfSubType.string, such as string.Enum5GTriggerType and Enum5GTriggerType.string.