From 38c0acc3d4691091f3c1dfd7e3f8f80e68a6f4f7 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 23 Feb 2021 16:03:07 +0100 Subject: [PATCH] [jOOQ/jOOQ#11504] Seralizability fix --- .../java/org/jooq/impl/DefaultBinding.java | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 9a2e81dd82..877d807dba 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -288,21 +288,30 @@ public class DefaultBinding implements Binding { else if (type == LocalDate.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(Date.class, LocalDate.class, Date::toLocalDate, Date::valueOf), + Converter.ofNullable(Date.class, LocalDate.class, + (Function & Serializable) Date::toLocalDate, + (Function & Serializable) Date::valueOf + ), (Converter) converter, c -> new DefaultDateBinding<>(DATE, c) ); else if (type == LocalDateTime.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(Timestamp.class, LocalDateTime.class, Timestamp::toLocalDateTime, Timestamp::valueOf), + Converter.ofNullable(Timestamp.class, LocalDateTime.class, + (Function & Serializable) Timestamp::toLocalDateTime, + (Function & Serializable) Timestamp::valueOf + ), (Converter) converter, c -> new DefaultTimestampBinding<>(TIMESTAMP, c) ); else if (type == LocalTime.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(Time.class, LocalTime.class, Time::toLocalTime, Time::valueOf), + Converter.ofNullable(Time.class, LocalTime.class, + (Function & Serializable) Time::toLocalTime, + (Function & Serializable) Time::valueOf + ), (Converter) converter, c -> new DefaultTimeBinding<>(TIME, c) ); @@ -333,28 +342,40 @@ public class DefaultBinding implements Binding { else if (type == UByte.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(Short.class, UByte.class, UByte::valueOf, UByte::shortValue), + Converter.ofNullable(Short.class, UByte.class, + (Function & Serializable) UByte::valueOf, + (Function & Serializable) UByte::shortValue + ), (Converter) converter, c -> new DefaultShortBinding<>(SMALLINT, c) ); else if (type == UInteger.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(Long.class, UInteger.class, UInteger::valueOf, UInteger::longValue), + Converter.ofNullable(Long.class, UInteger.class, + (Function & Serializable) UInteger::valueOf, + (Function & Serializable) UInteger::longValue + ), (Converter) converter, c -> new DefaultLongBinding<>(BIGINT, c) ); else if (type == ULong.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(BigInteger.class, ULong.class, ULong::valueOf, ULong::toBigInteger), + Converter.ofNullable(BigInteger.class, ULong.class, + (Function & Serializable) ULong::valueOf, + (Function & Serializable) ULong::toBigInteger + ), (Converter) converter, c -> new DefaultBigIntegerBinding<>(DECIMAL_INTEGER, c) ); else if (type == UShort.class) return (Binding) new DelegatingBinding<>( (DataType) dataType, - serializableConverter(Integer.class, UShort.class, UShort::valueOf, UShort::intValue), + Converter.ofNullable(Integer.class, UShort.class, + (Function & Serializable) UShort::valueOf, + (Function & Serializable) UShort::intValue + ), (Converter) converter, c -> new DefaultIntegerBinding<>(INTEGER, c) ); @@ -3175,11 +3196,11 @@ public class DefaultBinding implements Binding { */ private static final long serialVersionUID = -1850495302106551527L; - private static final Converter CONVERTER = serializableConverter( + private static final Converter CONVERTER = Converter.ofNullable( OffsetDateTime.class, Instant.class, - OffsetDateTime::toInstant, - i -> OffsetDateTime.ofInstant(i, ZoneOffset.UTC) + (Function & Serializable) OffsetDateTime::toInstant, + (Function & Serializable) i -> OffsetDateTime.ofInstant(i, ZoneOffset.UTC) ); private final DefaultOffsetDateTimeBinding delegate; @@ -4648,21 +4669,5 @@ public class DefaultBinding implements Binding { return Types.VARCHAR; } } - - /** - * Create a serializable converter. - */ - static final < - T, U, - FTU extends Function & Serializable, - FUT extends Function & Serializable - > Converter serializableConverter( - Class fromType, - Class toType, - FTU from, - FUT to - ) { - return Converter.ofNullable(fromType, toType, from, to); - } }