From d322ea4d6333bc904fff88146ad1d24cf6b03aa7 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 27 Aug 2020 16:09:19 +0200 Subject: [PATCH] [jOOQ/jOOQ#10532] Handle generics in .class literals --- .../org/jooq/meta/AbstractTypedElementDefinition.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/AbstractTypedElementDefinition.java b/jOOQ-meta/src/main/java/org/jooq/meta/AbstractTypedElementDefinition.java index ac9f09dbe1..d7e32a03e6 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/AbstractTypedElementDefinition.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/AbstractTypedElementDefinition.java @@ -228,12 +228,12 @@ public abstract class AbstractTypedElementDefinition if (Boolean.TRUE.equals(customType.isEnumConverter()) || EnumConverter.class.getName().equals(customType.getConverter())) { String tType = tType(db, resolver, definedType); - converter = "new " + EnumConverter.class.getName() + "<" + tType + ", " + uType + ">(" + tType + ".class, " + uType + ".class)"; + converter = "new " + EnumConverter.class.getName() + "<" + tType + ", " + uType + ">(" + classLiteral(tType) + ", " + classLiteral(uType) + ")"; } else if (customType.getLambdaConverter() != null) { LambdaConverter c = customType.getLambdaConverter(); String tType = tType(db, resolver, definedType); - converter = "org.jooq.Converter.of" + (!FALSE.equals(c.isNullable()) ? "Nullable" : "") + "(" + tType + ".class, " + uType + ".class, " + c.getFrom() + ", " + c.getTo() + ")"; + converter = "org.jooq.Converter.of" + (!FALSE.equals(c.isNullable()) ? "Nullable" : "") + "(" + classLiteral(tType) + ", " + classLiteral(uType) + ", " + c.getFrom() + ", " + c.getTo() + ")"; } else if (!StringUtils.isBlank(customType.getConverter())) { converter = customType.getConverter(); @@ -318,6 +318,11 @@ public abstract class AbstractTypedElementDefinition } } + private static final String classLiteral(String type) { + String rawtype = type.replaceAll("<.*>", "").replaceAll("\\[.*\\]", ""); + return (rawtype.equals(type) ? "" : "(java.lang.Class) ") + rawtype + ".class"; + } + @SuppressWarnings("deprecation") public static final CustomType customType(Database db, ForcedType forcedType) { String name = forcedType.getName();