From ce8b59501fba38d552454d2ee706b0387894c3bd Mon Sep 17 00:00:00 2001 From: Steven Schlansker Date: Wed, 8 Mar 2023 13:08:32 -0800 Subject: [PATCH] Add a new JakartaRsFeature to consume all content, on by default See https://github.com/FasterXML/jackson-jaxrs-providers/issues/108 --- .../fasterxml/jackson/jakarta/rs/base/ProviderBase.java | 3 +++ .../jackson/jakarta/rs/cfg/JakartaRSFeature.java | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/base/src/main/java/com/fasterxml/jackson/jakarta/rs/base/ProviderBase.java b/base/src/main/java/com/fasterxml/jackson/jakarta/rs/base/ProviderBase.java index e26fca8..ca32881 100644 --- a/base/src/main/java/com/fasterxml/jackson/jakarta/rs/base/ProviderBase.java +++ b/base/src/main/java/com/fasterxml/jackson/jakarta/rs/base/ProviderBase.java @@ -438,6 +438,9 @@ protected EP_CONFIG _configForReading(MAPPER mapper, } else { r = mapper.reader(); } + if (JakartaRSFeature.READ_FULL_STREAM.enabledIn(_jakartaRSFeatures)) { + r = r.withFeatures(DeserializationFeature.FAIL_ON_TRAILING_TOKENS); + } return _configForReading(r, annotations); } diff --git a/base/src/main/java/com/fasterxml/jackson/jakarta/rs/cfg/JakartaRSFeature.java b/base/src/main/java/com/fasterxml/jackson/jakarta/rs/cfg/JakartaRSFeature.java index 11afe47..0469ca3 100644 --- a/base/src/main/java/com/fasterxml/jackson/jakarta/rs/cfg/JakartaRSFeature.java +++ b/base/src/main/java/com/fasterxml/jackson/jakarta/rs/cfg/JakartaRSFeature.java @@ -24,6 +24,14 @@ public enum JakartaRSFeature implements ConfigFeature */ ALLOW_EMPTY_INPUT(true), + /** + * For HTTP keep-alive or multipart content to work correctly, Jackson must read the entire HTTP input + * stream up until reading EOF (-1). + * Issue #108 + * If set to true, always consume all input content. This has a side-effect of failing on trailing content. + */ + READ_FULL_STREAM(true), + /* /********************************************************************** /* HTTP headers