Skip to main content
Version: 1.13

Value Mapper SPI

The value mapper is used while evaluating expressions and unary tests to

  • transform a variable into a FEEL data type (e.g. when it is referenced in an expression x + 1)
  • transform the result of the expression or unary tests from a FEEL data type into a common data type (e.g. to String or BigDecimal/Long)

Using the SPI, the transformation can be customized to support more/custom data types, or changing the data type of the result.

Create a sub-class of org.camunda.feel.valuemapper.CustomValueMapper. Implement the method toVal() and unpackVal() to transform the object. Set the priority of the value mapper to define the precedence compared to the other mappers.

class MyValueMapper extends CustomValueMapper {

override def toVal(x: Any, innerValueMapper: Any => Val): Option[Val] = x match {
case c: Custom => Some(ValString(c.getName))
case _ => None
}

override def unpackVal(value: Val, innerValueMapper: Val => Any): Option[Any] = value match {
case ValNumber(number) => Some(number.doubleValue) // map BigDecimal to Double
case _ => None
}

override val priority: Int = 1

}

Register the Value Mapper

Depending how the FEEL engine is used, the value mapper can be passed directly on creation, or is loaded via Java ServiceLoader mechanism.

In the second case, create a new file org.camunda.feel.valuemapper.CustomValueMapper in the folder META-INF/services/. It must contain the full qualified name of the value mapper.

org.camunda.feel.example.valuemapper.MyValueMapper