Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove type from ResolverMapKey #36719

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class ClientJacksonMessageBodyReader extends JacksonBasicMessageBodyReade

private static final Logger log = Logger.getLogger(ClientJacksonMessageBodyReader.class);

private final ConcurrentMap<ResolverMapKey, ObjectMapper> contextResolverMap = new ConcurrentHashMap<>();
private final ConcurrentMap<ObjectMapper, ObjectReader> objectReaderMap = new ConcurrentHashMap<>();
private RestClientRequestContext context;

Expand All @@ -49,7 +48,7 @@ public Object readFrom(Class<Object> type, Type genericType, Annotation[] annota
if (entityStream instanceof EmptyInputStream) {
return null;
}
ObjectReader reader = getEffectiveReader(type, mediaType);
ObjectReader reader = getEffectiveReader(mediaType);
return reader.forType(reader.getTypeFactory().constructType(genericType != null ? genericType : type))
.readValue(entityStream);

Expand All @@ -66,8 +65,8 @@ public void handle(RestClientRequestContext requestContext) {
this.context = requestContext;
}

private ObjectReader getEffectiveReader(Class<Object> type, MediaType responseMediaType) {
ObjectMapper effectiveMapper = getObjectMapperFromContext(type, responseMediaType, context, contextResolverMap);
private ObjectReader getEffectiveReader(MediaType responseMediaType) {
ObjectMapper effectiveMapper = getObjectMapperFromContext(responseMediaType, context);
if (effectiveMapper == null) {
return getEffectiveReader();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class ClientJacksonMessageBodyWriter implements MessageBodyWriter<Object>

protected final ObjectMapper originalMapper;
protected final ObjectWriter defaultWriter;
private final ConcurrentMap<ResolverMapKey, ObjectMapper> contextResolverMap = new ConcurrentHashMap<>();
private final ConcurrentMap<ObjectMapper, ObjectWriter> objectWriterMap = new ConcurrentHashMap<>();
private RestClientRequestContext context;

Expand All @@ -46,16 +45,16 @@ public boolean isWriteable(Class type, Type genericType, Annotation[] annotation
@Override
public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
doLegacyWrite(o, annotations, httpHeaders, entityStream, getEffectiveWriter(type, mediaType));
doLegacyWrite(o, annotations, httpHeaders, entityStream, getEffectiveWriter(mediaType));
}

@Override
public void handle(RestClientRequestContext requestContext) throws Exception {
this.context = requestContext;
}

protected ObjectWriter getEffectiveWriter(Class<?> type, MediaType responseMediaType) {
ObjectMapper objectMapper = getObjectMapperFromContext(type, responseMediaType, context, contextResolverMap);
protected ObjectWriter getEffectiveWriter(MediaType responseMediaType) {
ObjectMapper objectMapper = getObjectMapperFromContext(responseMediaType, context);
if (objectMapper == null) {
return defaultWriter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.rest.client.reactive.jackson.runtime.serialisers;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;

Expand All @@ -13,11 +14,12 @@

final class JacksonUtil {

private static final ConcurrentMap<ResolverMapKey, ObjectMapper> contextResolverMap = new ConcurrentHashMap<>();

private JacksonUtil() {
}

static ObjectMapper getObjectMapperFromContext(Class<?> type, MediaType responseMediaType, RestClientRequestContext context,
ConcurrentMap<ResolverMapKey, ObjectMapper> contextResolverMap) {
static ObjectMapper getObjectMapperFromContext(MediaType responseMediaType, RestClientRequestContext context) {
Providers providers = getProviders(context);
if (providers == null) {
return null;
Expand All @@ -31,11 +33,11 @@ static ObjectMapper getObjectMapperFromContext(Class<?> type, MediaType response
}
if (contextResolver != null) {
var cr = contextResolver;
var key = new ResolverMapKey(type, context.getConfiguration(), context.getInvokedMethod().getDeclaringClass());
var key = new ResolverMapKey(context.getConfiguration(), context.getInvokedMethod().getDeclaringClass());
return contextResolverMap.computeIfAbsent(key, new Function<>() {
@Override
public ObjectMapper apply(ResolverMapKey resolverMapKey) {
return cr.getContext(resolverMapKey.getType());
return cr.getContext(resolverMapKey.getRestClientClass());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@
*/
public final class ResolverMapKey {

private final Class<?> type;
private final Configuration configuration;

private final Class<?> restClientClass;

public ResolverMapKey(Class<?> type, Configuration configuration, Class<?> restClientClass) {
this.type = type;
public ResolverMapKey(Configuration configuration, Class<?> restClientClass) {
this.configuration = configuration;
this.restClientClass = restClientClass;
}

public Class<?> getType() {
return type;
}

public Configuration getConfiguration() {
return configuration;
}
Expand All @@ -42,12 +35,12 @@ public boolean equals(Object o) {
return false;
}
ResolverMapKey that = (ResolverMapKey) o;
return Objects.equals(type, that.type) && Objects.equals(configuration, that.configuration)
return Objects.equals(configuration, that.configuration)
&& Objects.equals(restClientClass, that.restClientClass);
}

@Override
public int hashCode() {
return Objects.hash(type, configuration, restClientClass);
return Objects.hash(configuration, restClientClass);
}
}
Loading