Class TypeCoercionService

java.lang.Object
com.regnosys.rosetta.generator.java.expression.TypeCoercionService

public class TypeCoercionService extends Object
This service is responsible for coercing an expression from its actual Java type to an `expected` Java type. Both coercions of item types and of wrapper types are supported. Examples of supported coercions: - `Long` to `BigDecimal` - `BigInteger` to `Integer` (will throw a runtime exception if conversion looses information) - `Boolean` to `ComparisonResult` - `ComparisonResult` to `Boolean` - `String` to `MapperS` - `MapperC` to `List` - `MapperC` to `BigDecimal` - `MapperC` to `ComparisonResult` - `Void` to `LocalDate` - `Void` to `MapperC` Item to item coercions and item to wrapper coercions are performed null-safe. This service is auto-boxing aware. If the expected type is a wrapper class of a primitive type and the input expression is of a primitive type as well, the result will be of a primitive type. Terminology: - a "wrapper type" refers to any of the following classes: - `MapperS` - `MapperC` - `ComparisonResult` - `Mapper` (the general interface of the above classes) - `MapperListOfLists` - `List` - an "item type" refers to the type of the items of a wrapper type, or to the type itself if it does not refer to a wrapper type. For a precise definition, see the methods `JavaTypeUtil#isWrapper` and `JavaTypeUtil#getItemType`.