- All Superinterfaces:
Converter<T,,U> Serializable
- All Known Implementing Classes:
AbstractContextConverter,AutoConverter,Converters,DateToLocalDateConverter,DelegatingConverter,IdentityConverter,JPAConverter,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 URead 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> 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> Turn aConverterinto 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 TConvert 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.
-
Method Details
-
from
Read and convert a database object to a user object.- 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.- Parameters:
userObject- The user object.ctx- The context of this conversion.- Returns:
- The database object.
-
to
Description copied from interface:ConverterConvert and write a user object to a database object. -
from
Description copied from interface:ConverterRead and convert a database object to a user object. -
inverse
Inverse this converter. -
andThen
Chain a converter to this converter. -
forArrays
Turn this converter into a converter for arrays. -
scoped
Turn aConverterinto 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.- 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.- 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.- 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:
-
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 conversionFunctions are decorated with a function that always returnsnullfornullinputs.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.- 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 conversionFunctionis decorated with a function that always returnsnullfornullinputs.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:
-
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 conversionFunctionis decorated with a function that always returnsnullfornullinputs.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 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:
-