diff --git a/extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveCommonRecorder.java b/extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveCommonRecorder.java index b5044a6331e8e..b7e5ef4133566 100644 --- a/extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveCommonRecorder.java +++ b/extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ResteasyReactiveCommonRecorder.java @@ -34,7 +34,7 @@ public void registerWriter(Serialisers serialisers, String entityClassName, public void registerReader(Serialisers serialisers, String entityClassName, ResourceReader reader) { - serialisers.addReader(loadClass(entityClassName), reader); + serialisers.addReader(entityClassName, reader); } protected static Class loadClass(String name) { diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientSerialisers.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientSerialisers.java index fc837e422aae4..1b29b475cc7af 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientSerialisers.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientSerialisers.java @@ -202,7 +202,7 @@ public void registerBuiltins(RuntimeType constraint) { resourceReader.setMediaTypeStrings(Collections.singletonList(builtinReader.mediaType)); // FIXME: we could still support beans resourceReader.setFactory(new UnmanagedBeanFactory>(reader)); - addReader(builtinReader.entityClass, resourceReader); + addReader(builtinReader.entityClass.getName(), resourceReader); } } } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java index 26bbcc8d75c87..64097610c387a 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java @@ -32,7 +32,10 @@ public abstract class Serialisers { public static final WriterInterceptor[] NO_WRITER_INTERCEPTOR = new WriterInterceptor[0]; // FIXME: spec says we should use generic type, but not sure how to pass that type from Jandex to reflection protected final QuarkusMultivaluedMap, ResourceWriter> writers = new QuarkusMultivaluedHashMap<>(); - protected final QuarkusMultivaluedMap, ResourceReader> readers = new QuarkusMultivaluedHashMap<>(); + // for readers the key is a string in order to avoid loading all the reader classes at startup + // for writers we can't really do the same trick because we need to go through (potentially) all the writers + // at startup in order to determine the writer used for each resource method + protected final QuarkusMultivaluedMap readers = new QuarkusMultivaluedHashMap<>(); public List> findReaders(ConfigurationImpl configuration, Class entityType, MediaType mediaType) { @@ -45,7 +48,7 @@ public List> findReaders(ConfigurationImpl configuration, C List> ret = new ArrayList<>(); Deque> toProcess = new LinkedList<>(); Class klass = lookupPrimitiveWrapper(entityType); - QuarkusMultivaluedMap, ResourceReader> readers; + QuarkusMultivaluedMap readers; if (configuration != null && !configuration.getResourceReaders().isEmpty()) { readers = new QuarkusMultivaluedHashMap<>(); readers.addAll(configuration.getResourceReaders()); @@ -61,7 +64,7 @@ public List> findReaders(ConfigurationImpl configuration, C Set> seen = new HashSet<>(toProcess); while (!toProcess.isEmpty()) { Class iface = toProcess.poll(); - List goodTypeReaders = readers.get(iface); + List goodTypeReaders = readers.get(iface.getName()); readerLookup(mediaType, runtimeType, desired, ret, goodTypeReaders); for (Class i : iface.getInterfaces()) { if (!seen.contains(i)) { @@ -71,7 +74,7 @@ public List> findReaders(ConfigurationImpl configuration, C } } } - List goodTypeReaders = readers.get(klass); + List goodTypeReaders = readers.get(klass.getName()); readerLookup(mediaType, runtimeType, desired, ret, goodTypeReaders); if (klass.isInterface()) { klass = Object.class; @@ -111,8 +114,8 @@ public void addWriter(Class entityClass, ResourceWriter writer) { writers.add(entityClass, writer); } - public void addReader(Class entityClass, ResourceReader reader) { - readers.add(entityClass, reader); + public void addReader(String entityClassName, ResourceReader reader) { + readers.add(entityClassName, reader); } public List> findBuildTimeWriters(Class entityType, RuntimeType runtimeType, diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java index 26af7a3155e4e..adfe32e05ed22 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java @@ -52,7 +52,7 @@ public class ConfigurationImpl implements Configuration { private final MultivaluedMap writerInterceptors; private final MultivaluedMap readerInterceptors; private final MultivaluedMap, ResourceWriter> resourceWriters; - private final MultivaluedMap, ResourceReader> resourceReaders; + private final MultivaluedMap resourceReaders; private final MultivaluedMap, RxInvokerProvider> rxInvokerProviders; private final Map, MultivaluedMap>> contextResolvers; @@ -284,8 +284,8 @@ private void register(Object component, Integer priority) { resourceReader.setPriority(priority); } Type[] args = Types.findParameterizedTypes(componentClass, MessageBodyReader.class); - resourceReaders.add(args != null && args.length == 1 ? Types.getRawType(args[0]) : Object.class, - resourceReader); + Class clazz = args != null && args.length == 1 ? Types.getRawType(args[0]) : Object.class; + resourceReaders.add(clazz.getName(), resourceReader); } } if (component instanceof MessageBodyWriter) { @@ -404,8 +404,8 @@ public void register(Object component, Map, Integer> componentContracts .setMediaTypeStrings( consumes != null ? Arrays.asList(consumes.value()) : WILDCARD_STRING_LIST); Type[] args = Types.findParameterizedTypes(componentClass, MessageBodyReader.class); - resourceReaders.add(args != null && args.length == 1 ? Types.getRawType(args[0]) : Object.class, - resourceReader); + Class clazz = args != null && args.length == 1 ? Types.getRawType(args[0]) : Object.class; + resourceReaders.add(clazz.getName(), resourceReader); } } priority = componentContracts.get(MessageBodyWriter.class); @@ -455,7 +455,7 @@ public void registerMessageBodyReader(MessageBodyReader reader, Class hand resourceReader.setBuiltin(builtin); resourceReader.setPriority(priority); resourceReader.setConstraint(runtimeType); - resourceReaders.add(handledType, resourceReader); + resourceReaders.add(handledType.getName(), resourceReader); allInstances.put(reader.getClass(), reader); } @@ -578,7 +578,7 @@ private int determinePriority(Class object) { return priority.value(); } - public MultivaluedMap, ResourceReader> getResourceReaders() { + public MultivaluedMap getResourceReaders() { return resourceReaders; } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/DeploymentUtils.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/DeploymentUtils.java index 95694a4dbf612..e6da5a06b4a4e 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/DeploymentUtils.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/DeploymentUtils.java @@ -3,7 +3,6 @@ import java.util.Map; import org.jboss.resteasy.reactive.common.core.Serialisers; -import org.jboss.resteasy.reactive.common.model.ResourceReader; import org.jboss.resteasy.reactive.common.model.ResourceWriter; public abstract class DeploymentUtils { @@ -22,11 +21,6 @@ public static void registerWriter(Serialisers serialisers, String entityClassNam serialisers.addWriter(loadClass(entityClassName), writer); } - public static void registerReader(Serialisers serialisers, String entityClassName, - ResourceReader reader) { - serialisers.addReader(loadClass(entityClassName), reader); - } - public static Class loadClass(String name) { if (primitiveTypes.containsKey(name)) { return (Class) primitiveTypes.get(name); diff --git a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ResteasyReactiveDeploymentManager.java b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ResteasyReactiveDeploymentManager.java index 2435451e36e41..a179f5bd018b2 100644 --- a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ResteasyReactiveDeploymentManager.java +++ b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ResteasyReactiveDeploymentManager.java @@ -346,7 +346,7 @@ public void addScannedSerializers() throws ClassNotFoundException { .setFactory(new ReflectionBeanFactory<>(i.getClassName()))); } for (var i : sa.serializerScanningResult.getReaders()) { - serialisers.addReader(classLoader.loadClass(i.getHandledClassName()), + serialisers.addReader(i.getHandledClassName(), new ResourceReader() .setMediaTypeStrings(i.getMediaTypeStrings()) .setConstraint(i.getRuntimeType()) @@ -361,7 +361,7 @@ public void addScannedSerializers() throws ClassNotFoundException { .setMediaTypeStrings(Collections.singletonList(i.getMediaType()))); } for (var i : sa.readers.get()) { - serialisers.addReader(classLoader.loadClass(i.getEntityClass()), + serialisers.addReader(i.getEntityClass(), new ResourceReader().setFactory(ReflectiveContextInjectedBeanFactory.create((i.getHandlerClass()))) .setConstraint(i.getConstraint()) .setMediaTypeStrings(Collections.singletonList(i.getMediaType()))); @@ -370,7 +370,7 @@ public void addScannedSerializers() throws ClassNotFoundException { public void addBuiltinSerializers() { for (Serialisers.BuiltinReader builtinReader : ServerSerialisers.BUILTIN_READERS) { - serialisers.addReader(builtinReader.entityClass, + serialisers.addReader(builtinReader.entityClass.getName(), new ResourceReader().setFactory(ReflectiveContextInjectedBeanFactory.create(builtinReader.readerClass)) .setConstraint(builtinReader.constraint) .setMediaTypeStrings(Collections.singletonList(builtinReader.mediaType)).setBuiltin(true)); diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java index e5b51941aa3ff..80135b30fa623 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ServerSerialisers.java @@ -39,7 +39,6 @@ import org.jboss.resteasy.reactive.common.core.Serialisers; import org.jboss.resteasy.reactive.common.headers.HeaderUtil; import org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl; -import org.jboss.resteasy.reactive.common.model.ResourceReader; import org.jboss.resteasy.reactive.common.model.ResourceWriter; import org.jboss.resteasy.reactive.common.util.MediaTypeHelper; import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap; @@ -271,10 +270,6 @@ public MultivaluedMap, ResourceWriter> getWriters() { return writers; } - public MultivaluedMap, ResourceReader> getReaders() { - return readers; - } - /** * Find the best matching writer based on the 'Accept' HTTP header * This is probably more complex than it needs to be, but some RESTEasy tests show that the response type