diff --git a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java
index e7812439b4..cd104d41cb 100644
--- a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java
+++ b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java
@@ -34,7 +34,11 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
/**
- * Implementation of {@code HttpMessageReader} delegating to a {@link Decoder}.
+ * {@code HttpMessageReader} that wraps and delegates to a {@link Decoder}.
+ *
+ *
Also a {@code ServerHttpMessageReader} that pre-resolves decoding hints
+ * from the extra information available on the server side such as the request
+ * or controller method parameter annotations.
*
* @author Arjen Poutsma
* @author Sebastien Deleuze
@@ -105,7 +109,7 @@ public class DecoderHttpMessageReader implements ServerHttpMessageReader {
ServerHttpRequest request, ServerHttpResponse response, Map hints) {
Map allHints = new HashMap<>(4);
- allHints.putAll(resolveReadHints(streamType, elementType, request, response));
+ allHints.putAll(getReadHints(streamType, elementType, request, response));
allHints.putAll(hints);
return read(elementType, request, allHints);
@@ -116,19 +120,24 @@ public class DecoderHttpMessageReader implements ServerHttpMessageReader {
ServerHttpRequest request, ServerHttpResponse response, Map hints) {
Map allHints = new HashMap<>(4);
- allHints.putAll(resolveReadHints(streamType, elementType, request, response));
+ allHints.putAll(getReadHints(streamType, elementType, request, response));
allHints.putAll(hints);
return readMono(elementType, request, allHints);
}
/**
- * Resolve hints to pass to the decoder, e.g. by checking for annotations
- * on a controller method parameter or checking the server request.
+ * Get additional hints for decoding for example based on the server request
+ * or annotations from controller method parameters. By default, delegate to
+ * the decoder if it is an instance of {@link ServerHttpDecoder}.
*/
- protected Map resolveReadHints(ResolvableType streamType,
+ protected Map getReadHints(ResolvableType streamType,
ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response) {
+ if (this.decoder instanceof ServerHttpDecoder) {
+ ServerHttpDecoder> httpDecoder = (ServerHttpDecoder>) this.decoder;
+ return httpDecoder.getDecodeHints(streamType, elementType, request, response);
+ }
return Collections.emptyMap();
}
diff --git a/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java
index 3ae2f9ddac..9dbfe37f8f 100644
--- a/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java
+++ b/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java
@@ -39,7 +39,11 @@ import static org.springframework.core.codec.AbstractEncoder.FLUSHING_STRATEGY_H
import static org.springframework.core.codec.AbstractEncoder.FlushingStrategy.AFTER_EACH_ELEMENT;
/**
- * Implementation of {@code HttpMessageWriter} delegating to an {@link Encoder}.
+ * {@code HttpMessageWriter} that wraps and delegates to a {@link Encoder}.
+ *
+ *
Also a {@code ServerHttpMessageWriter} that pre-resolves encoding hints
+ * from the extra information available on the server side such as the request
+ * or controller method annotations.
*
* @author Arjen Poutsma
* @author Sebastien Deleuze
@@ -132,19 +136,24 @@ public class EncoderHttpMessageWriter implements ServerHttpMessageWriter {
ServerHttpResponse response, Map hints) {
Map allHints = new HashMap<>();
- allHints.putAll(resolveWriteHints(streamType, elementType, mediaType, request, response));
+ allHints.putAll(getWriteHints(streamType, elementType, mediaType, request, response));
allHints.putAll(hints);
return write(inputStream, elementType, mediaType, response, allHints);
}
/**
- * Resolve hints to pass to the encoder, e.g. by checking for annotations
- * on a controller method parameter or checking the server request.
+ * Get additional hints for encoding for example based on the server request
+ * or annotations from controller method parameters. By default, delegate to
+ * the encoder if it is an instance of {@link ServerHttpEncoder}.
*/
- protected Map resolveWriteHints(ResolvableType streamType, ResolvableType elementType,
+ protected Map getWriteHints(ResolvableType streamType, ResolvableType elementType,
MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) {
+ if (this.encoder instanceof ServerHttpEncoder) {
+ ServerHttpEncoder> httpEncoder = (ServerHttpEncoder>) this.encoder;
+ return httpEncoder.getEncodeHints(streamType, elementType, mediaType, request, response);
+ }
return Collections.emptyMap();
}
diff --git a/spring-web/src/main/java/org/springframework/http/codec/Jackson2ServerHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/Jackson2ServerHttpMessageReader.java
deleted file mode 100644
index 50da50349a..0000000000
--- a/spring-web/src/main/java/org/springframework/http/codec/Jackson2ServerHttpMessageReader.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2002-2017 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.http.codec;
-
-import java.util.Collections;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonView;
-
-import org.springframework.core.MethodParameter;
-import org.springframework.core.ResolvableType;
-import org.springframework.core.codec.Decoder;
-import org.springframework.http.codec.json.AbstractJackson2Codec;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-
-/**
- * {@link ServerHttpMessageReader} that resolves those annotation or request based Jackson 2 hints:
- *