Skip to content

Commit 6cc2b9c

Browse files
committed
Updates to jackson 3
Fixes gh-4001
1 parent 8769340 commit 6cc2b9c

File tree

1 file changed

+8
-11
lines changed
  • spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter

1 file changed

+8
-11
lines changed

spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/AfterFilterFunctions.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import java.util.function.Consumer;
2626
import java.util.regex.Pattern;
2727

28-
import com.fasterxml.jackson.core.JsonProcessingException;
29-
import com.fasterxml.jackson.databind.JsonNode;
30-
import com.fasterxml.jackson.databind.ObjectMapper;
31-
import com.fasterxml.jackson.databind.node.ObjectNode;
3228
import org.jspecify.annotations.Nullable;
29+
import tools.jackson.core.JacksonException;
30+
import tools.jackson.databind.JsonNode;
31+
import tools.jackson.databind.json.JsonMapper;
32+
import tools.jackson.databind.node.ObjectNode;
3333

3434
import org.springframework.cloud.gateway.server.mvc.common.HttpStatusHolder;
3535
import org.springframework.cloud.gateway.server.mvc.common.MvcUtils;
@@ -49,8 +49,6 @@
4949
*/
5050
public abstract class AfterFilterFunctions {
5151

52-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
53-
5452
private AfterFilterFunctions() {
5553
}
5654

@@ -192,15 +190,14 @@ public static BiFunction<ServerRequest, ServerResponse, ServerResponse> removeJs
192190

193191
return modifyResponseBody(String.class, String.class, APPLICATION_JSON_VALUE, (request, response, body) -> {
194192
String responseBody = body;
193+
JsonMapper jsonMapper = MvcUtils.getApplicationContext(request).getBean(JsonMapper.class);
195194
if (APPLICATION_JSON.isCompatibleWith(response.headers().getContentType())) {
196195
try {
197-
JsonNode jsonBodyContent = OBJECT_MAPPER.readValue(responseBody, JsonNode.class);
198-
196+
JsonNode jsonBodyContent = jsonMapper.readValue(responseBody, JsonNode.class);
199197
removeJsonAttributes(jsonBodyContent, immutableFieldList, deleteRecursively);
200-
201-
responseBody = OBJECT_MAPPER.writeValueAsString(jsonBodyContent);
198+
responseBody = jsonMapper.writeValueAsString(jsonBodyContent);
202199
}
203-
catch (JsonProcessingException exception) {
200+
catch (JacksonException exception) {
204201
throw new IllegalStateException("Failed to process JSON of response body.", exception);
205202
}
206203
}

0 commit comments

Comments
 (0)