From a1e0bc360f71510de3fc2a418549c34315163be2 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Fri, 23 Jun 2023 12:45:35 -0400 Subject: [PATCH] Fix parser registry not properly resolving `TypeToken` Use `AnnotatedTypeMap` instead of `HashMap` for the parser registry, as recommended by leangen/geantyref#17 Signed-off-by: solonovamax --- .../arguments/parser/StandardParserRegistry.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java index 64a1b4647..e19920448 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java @@ -42,9 +42,11 @@ import cloud.commandframework.arguments.standard.StringArrayArgument; import cloud.commandframework.arguments.standard.UUIDArgument; import cloud.commandframework.context.CommandContext; +import io.leangen.geantyref.AnnotatedTypeMap; import io.leangen.geantyref.GenericTypeReflector; import io.leangen.geantyref.TypeToken; import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedType; import java.time.Duration; import java.util.Arrays; import java.util.Collection; @@ -85,7 +87,7 @@ public final class StandardParserRegistry implements ParserRegistry { }; private final Map>> namedParsers = new HashMap<>(); - private final Map, Function>> parserSuppliers = new HashMap<>(); + private final Map>> parserSuppliers = new AnnotatedTypeMap<>(); private final Map, BiFunction, ParserParameters>> annotationMappers = new HashMap<>(); private final Map, @NonNull String, @NonNull List>> @@ -190,7 +192,7 @@ public void registerParserSupplier( final @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser> supplier ) { - this.parserSuppliers.put(type, supplier); + this.parserSuppliers.put(type.getAnnotatedType(), supplier); } @Override @@ -243,7 +245,7 @@ public void registerAnnotationMapper( } else { actualType = type; } - final Function> producer = this.parserSuppliers.get(actualType); + final Function> producer = this.parserSuppliers.get(actualType.getAnnotatedType()); if (producer == null) { /* Give enums special treatment */ if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {