Interface ICoercionProvider


  • public interface ICoercionProvider
    Implement this interface to handle coercions during dynamic proxy invocation, such as with JSON Schema marshalling. Note if you intend to implement JSON coercions you should instead implement IJsonFormatTypeCoercer.

    See IJsonFormatTypeCoercer

    • Method Detail

      • coerce

        Object coerce​(Object value,
                      Type type)
        Coerce value to type. Return ICallHandler.UNHANDLED if not coerced. It is imperative that this method coerces only between the JSON types and Java types it explicitly handles otherwise you may inadvertently perform a coercion that is incorrect that is better handled by another coercion provider.
        Parameters:
        value - A value to coerce, typically a String.
        type - The type to convert to.
        Returns:
        A value of the specified type or ICallHandler.UNHANDLED if this provider does not handle the coercion.
      • toBindingValue

        Object toBindingValue​(Object value)
        Coerce value parameter to a value suitable for a Bindings e.g., a JSON bindings. It is imperative that this method coerces only between the JSON types and Java types it explicitly handles otherwise you may inadvertently perform a coercion that is incorrect that is better handled by another coercion provider.
        Parameters:
        value - A value to coerce.
        Returns:
        A value suitable for a Bindings or ICallHandler.UNHANDLED if this provider does not handle the coercion. For example, the coerced value is typically a String when dealing with JSON Schema formats such as "date-time" where the value persists in the bindings as a String, but surfaces as a LocalDateTime in the Java API.