Skip to content

Commit

Permalink
Make contextResolverMap used for both reader and writer
Browse files Browse the repository at this point in the history
  • Loading branch information
manofthepeace committed Oct 27, 2023
1 parent ffc8a2a commit 6f5648c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
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 Down

0 comments on commit 6f5648c

Please sign in to comment.