Class Conversions


  • public final class Conversions
    extends Object
    Defines basic type conversions. This class is mostly intended for internal use only but its methods are public so that when cases arise where certain conversions are missing, users can add their in between releases. However, this must be done with the understand that, however unlikely, this API is subject to change and any uses might break at some point.
    Developer note.
    This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    • Method Detail

      • register

        public static <S,​T> void register​(Class<S> source,
                                                Class<T> target,
                                                Function<S,​T> function)
        Register a conversion between two types. For example, to register the conversion of Date to a Long, this method could be invoked as follows: register(Date.class, Long.class, Date::getTime);
        Type Parameters:
        S - the source type
        T - the target type.
        Parameters:
        source - the source type
        target - the target type
        function - the function that performs the conversion. This is often just a method reference.
      • convert

        public static <T> T convert​(Object value,
                                    Class<T> target)
        Attempts to convert a value to the given type
        Type Parameters:
        T - the target type
        Parameters:
        value - the value to convert
        target - the target type
        Returns:
        the potentially converted value
      • register

        public static <S,​T> void register​(Class<S> source,
                                                Class<T> target,
                                                Function<S,​T> function,
                                                String warning)
        Register a conversion between two types. For example, to register the conversion of Date to a Long, this method could be invoked as follows: register(Date.class, Long.class, Date::getTime);
        Type Parameters:
        S - the source type
        T - the target type.
        Parameters:
        source - the source type
        target - the target type
        function - the function that performs the conversion. This is often just a method reference.
        warning - if non-null, this will be the message logged on the WARN level indicating the conversion is taking place.