Module org.jooq
Package org.jooq

Interface Converter<T,​U>

    • Method Detail

      • from

        U from​(T databaseObject)
        Read and convert a database object to a user object.
        Parameters:
        databaseObject - The database object.
        Returns:
        The user object.
      • to

        T to​(U userObject)
        Convert and write a user object to a database object.
        Parameters:
        userObject - The user object.
        Returns:
        The database object.
      • fromType

        @NotNull
        @NotNull Class<T> fromType()
        The database type.
      • toType

        @NotNull
        @NotNull Class<U> toType()
        The user type.
      • inverse

        @NotNull
        default @NotNull Converter<U,​T> inverse()
        Inverse this converter.
      • andThen

        @NotNull
        default <X> @NotNull Converter<T,​X> andThen​(Converter<? super U,​X> converter)
        Chain a converter to this converter.
      • forArrays

        @NotNull
        default @NotNull Converter<T[],​U[]> forArrays()
        Turn this converter into a converter for arrays.
      • of

        @NotNull
        static <T,​U> @NotNull Converter<T,​U> of​(Class<T> fromType,
                                                            Class<U> toType,
                                                            Function<? super T,​? extends U> from,
                                                            Function<? super U,​? extends T> to)
        Construct a new converter from functions.
        Type Parameters:
        T - the database type.
        U - the user type.
        Parameters:
        fromType - The database type.
        toType - The user type.
        from - A function converting from T to U when reading from the database.
        to - A function converting from U to T when writing to the database.
        Returns:
        The converter.
        See Also:
        Converter
      • from

        @NotNull
        static <T,​U> @NotNull Converter<T,​U> from​(Class<T> fromType,
                                                              Class<U> toType,
                                                              Function<? super T,​? extends U> from)
        Construct a new read-only converter from a function.
        Type Parameters:
        T - the database type
        U - the user type
        Parameters:
        fromType - The database type
        toType - The user type
        from - A function converting from T to U when reading from the database.
        to - A function converting from U to T when writing to the database.
        Returns:
        The converter.
        See Also:
        Converter
      • to

        @NotNull
        static <T,​U> @NotNull Converter<T,​U> to​(Class<T> fromType,
                                                            Class<U> toType,
                                                            Function<? super U,​? extends T> to)
        Construct a new write-only converter from a function.
        Type Parameters:
        T - the database type
        U - the user type
        Parameters:
        fromType - The database type
        toType - The user type
        from - A function converting from T to U when reading from the database.
        to - A function converting from U to T when writing to the database.
        Returns:
        The converter.
        See Also:
        Converter
      • ofNullable

        @NotNull
        static <T,​U> @NotNull Converter<T,​U> ofNullable​(Class<T> fromType,
                                                                    Class<U> toType,
                                                                    Function<? super T,​? extends U> from,
                                                                    Function<? super U,​? extends T> to)
        Construct a new converter from functions.

        This works like of(Class, Class, Function, Function), except that both conversion Functions are decorated with a function that always returns null for null inputs.

        Example:

        
         Converter<String, Integer> converter =
           Converter.ofNullable(String.class, Integer.class, Integer::parseInt, Object::toString);
        
         // No exceptions thrown
         assertNull(converter.from(null));
         assertNull(converter.to(null));
         
        Type Parameters:
        T - the database type
        U - the user type
        Parameters:
        fromType - The database type
        toType - The user type
        from - A function converting from T to U when reading from the database.
        to - A function converting from U to T when writing to the database.
        Returns:
        The converter.
        See Also:
        Converter
      • fromNullable

        @NotNull
        static <T,​U> @NotNull Converter<T,​U> fromNullable​(Class<T> fromType,
                                                                      Class<U> toType,
                                                                      Function<? super T,​? extends U> from)
        Construct a new read-only converter from a function.

        This works like from(Class, Class, Function), except that the conversion Function is decorated with a function that always returns null for null inputs.

        Example:

        
         Converter<String, Integer> converter =
           Converter.fromNullable(String.class, Integer.class, Integer::parseInt);
        
         // No exceptions thrown
         assertNull(converter.from(null));
         
        Type Parameters:
        T - the database type.
        U - the user type.
        Parameters:
        fromType - The database type.
        toType - The user type.
        from - A function converting from T to U when reading from the database.
        Returns:
        The converter.
        See Also:
        Converter
      • toNullable

        @NotNull
        static <T,​U> @NotNull Converter<T,​U> toNullable​(Class<T> fromType,
                                                                    Class<U> toType,
                                                                    Function<? super U,​? extends T> to)
        Construct a new write-only converter from a function.

        This works like to(Class, Class, Function), except that the conversion Function is decorated with a function that always returns null for null inputs.

        Example:

        
         Converter<String, Integer> converter =
           Converter.toNullable(String.class, Integer.class, Object::toString);
        
         // No exceptions thrown
         assertNull(converter.to(null));
         
        Type Parameters:
        T - the database type
        U - the user type
        Parameters:
        fromType - The database type
        toType - The user type
        to - A function converting from U to T when writing to the database.
        Returns:
        The converter.
        See Also:
        Converter