- All Superinterfaces:
Converter<T,
,U> Serializable
- All Known Implementing Classes:
AbstractContextConverter
,AutoConverter
,Converters
,DateToLocalDateConverter
,DelegatingConverter
,IdentityConverter
,TimestampToLocalDateTimeConverter
,TimeToLocalTimeConverter
Converter
with alternative
from(Object, ConverterContext)
and
to(Object, ConverterContext)
methods.
This special converter type can be used wherever an ordinary
Converter
is used. jOOQ internal call sites will call the alternative
from(Object, ConverterContext)
and
to(Object, ConverterContext)
methods, instead of
from(Object)
and to(Object)
, allowing for accessing global
Configuration.data()
content.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <X> @NotNull ContextConverter
<T, X> Chain a converter to this converter.default @NotNull ContextConverter
<T[], U[]> Turn this converter into a converter for arrays.static <T,
U> @NotNull ContextConverter <T, U> from
(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from) Construct a new read-only converter from a function.default U
Read and convert a database object to a user object.from
(T databaseObject, ConverterContext ctx) Read and convert a database object to a user object.static <T,
U> @NotNull Converter <T, U> fromNullable
(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from) Construct a new read-only converter from a function.default @NotNull ContextConverter
<U, T> inverse()
Inverse this converter.static <T,
U> @NotNull ContextConverter <T, U> of
(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new converter from functions.static <T,
U> @NotNull ContextConverter <T, U> of
(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to, boolean fromSupported, boolean toSupported) Construct a new converter from functions.static <T,
U> @NotNull ContextConverter <T, U> ofNullable
(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new converter from functions.static <T,
U> @NotNull ContextConverter <T, U> ofNullable
(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to, boolean fromSupported, boolean toSupported) Construct a new converter from functions.static <T,
U> @NotNull ContextConverter <T, U> Turn aConverter
into aContextConverter
.static <T,
U> @NotNull ContextConverter <T, U> to
(Class<T> fromType, Class<U> toType, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new write-only converter from a function.default T
Convert and write a user object to a database object.to
(U userObject, ConverterContext ctx) Convert and write a user object to a database object.static <T,
U> @NotNull Converter <T, U> toNullable
(Class<T> fromType, Class<U> toType, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new write-only converter from a function.Methods inherited from interface org.jooq.Converter
fromSupported, fromType, toSupported, toType
-
Method Details
-
from
Read and convert a database object to a user object.Implementations that don't support this conversion are expected to override
Converter.fromSupported()
to indicate lack of support.- Parameters:
databaseObject
- The database object.ctx
- The context of this conversion.- Returns:
- The user object.
-
to
Convert and write a user object to a database object.Implementations that don't support this conversion are expected to override
Converter.toSupported()
to indicate lack of support.- Parameters:
userObject
- The user object.ctx
- The context of this conversion.- Returns:
- The database object.
-
to
Description copied from interface:Converter
Convert and write a user object to a database object.Implementations that don't support this conversion are expected to override
Converter.toSupported()
to indicate lack of support. -
from
Description copied from interface:Converter
Read and convert a database object to a user object.Implementations that don't support this conversion are expected to override
Converter.fromSupported()
to indicate lack of support. -
inverse
Inverse this converter. -
andThen
Chain a converter to this converter. -
forArrays
Turn this converter into a converter for arrays. -
scoped
Turn aConverter
into aContextConverter
. -
from
@NotNull static <T,U> @NotNull ContextConverter<T,U> from(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from) Construct a new read-only converter from a function.The resulting
Converter
returns false onConverter.toSupported()
.- Type Parameters:
T
- the database typeU
- the user type- Parameters:
fromType
- The database typetoType
- The user typefrom
- 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:
-
to
@NotNull static <T,U> @NotNull ContextConverter<T,U> to(Class<T> fromType, Class<U> toType, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new write-only converter from a function.The resulting
Converter
returns false onConverter.fromSupported()
.- Type Parameters:
T
- the database typeU
- the user type- Parameters:
fromType
- The database typetoType
- The user typeto
- A function converting from U to T when writing to the database.from
- A function converting from T to U when reading from the database.- Returns:
- The converter.
- See Also:
-
of
@NotNull static <T,U> @NotNull ContextConverter<T,U> of(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new converter from functions.The resulting
Converter
is expected to returntrue
on bothConverter.fromSupported()
andConverter.toSupported()
.- 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:
-
of
@NotNull static <T,U> @NotNull ContextConverter<T,U> of(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to, boolean fromSupported, boolean toSupported) 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.fromSupported
- Whether the from function is supported.toSupported
- Whether the to function is supported.- Returns:
- The converter.
- See Also:
-
ofNullable
@NotNull static <T,U> @NotNull ContextConverter<T,U> ofNullable(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new converter from functions.This works like
Converter.of(Class, Class, Function, Function)
, except that both conversionFunction
s are decorated with a function that always returnsnull
fornull
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));
The resulting
Converter
is expected to returntrue
on bothConverter.fromSupported()
andConverter.toSupported()
.- Type Parameters:
T
- the database typeU
- the user type- Parameters:
fromType
- The database typetoType
- The user typefrom
- 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:
-
ofNullable
@NotNull static <T,U> @NotNull ContextConverter<T,U> ofNullable(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from, BiFunction<? super U, ? super ConverterContext, ? extends T> to, boolean fromSupported, boolean toSupported) Construct a new converter from functions.This works like
Converter.of(Class, Class, Function, Function)
, except that both conversionFunction
s are decorated with a function that always returnsnull
fornull
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 typeU
- the user type- Parameters:
fromType
- The database typetoType
- The user typefrom
- 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.fromSupported
- Whether the from function is supported.toSupported
- Whether the to function is supported.- Returns:
- The converter.
- See Also:
-
fromNullable
@NotNull static <T,U> @NotNull Converter<T,U> fromNullable(Class<T> fromType, Class<U> toType, BiFunction<? super T, ? super ConverterContext, ? extends U> from) Construct a new read-only converter from a function.This works like
Converter.from(Class, Class, Function)
, except that the conversionFunction
is decorated with a function that always returnsnull
fornull
inputs.Example:
Converter<String, Integer> converter = Converter.fromNullable(String.class, Integer.class, Integer::parseInt); // No exceptions thrown assertNull(converter.from(null));
The resulting
Converter
returns false onConverter.toSupported()
.- 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:
-
toNullable
@NotNull static <T,U> @NotNull Converter<T,U> toNullable(Class<T> fromType, Class<U> toType, BiFunction<? super U, ? super ConverterContext, ? extends T> to) Construct a new write-only converter from a function.This works like
Converter.to(Class, Class, Function)
, except that the conversionFunction
is decorated with a function that always returnsnull
fornull
inputs.Example:
Converter<String, Integer> converter = Converter.toNullable(String.class, Integer.class, Object::toString); // No exceptions thrown assertNull(converter.to(null));
The resulting
Converter
returns false onConverter.fromSupported()
.- Type Parameters:
T
- the database typeU
- the user type- Parameters:
fromType
- The database typetoType
- The user typeto
- A function converting from U to T when writing to the database.- Returns:
- The converter.
- See Also:
-