|
25 | 25 | import java.util.function.Consumer; |
26 | 26 | import java.util.regex.Pattern; |
27 | 27 |
|
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; |
32 | 28 | 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; |
33 | 33 |
|
34 | 34 | import org.springframework.cloud.gateway.server.mvc.common.HttpStatusHolder; |
35 | 35 | import org.springframework.cloud.gateway.server.mvc.common.MvcUtils; |
|
49 | 49 | */ |
50 | 50 | public abstract class AfterFilterFunctions { |
51 | 51 |
|
52 | | - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
53 | | - |
54 | 52 | private AfterFilterFunctions() { |
55 | 53 | } |
56 | 54 |
|
@@ -192,15 +190,14 @@ public static BiFunction<ServerRequest, ServerResponse, ServerResponse> removeJs |
192 | 190 |
|
193 | 191 | return modifyResponseBody(String.class, String.class, APPLICATION_JSON_VALUE, (request, response, body) -> { |
194 | 192 | String responseBody = body; |
| 193 | + JsonMapper jsonMapper = MvcUtils.getApplicationContext(request).getBean(JsonMapper.class); |
195 | 194 | if (APPLICATION_JSON.isCompatibleWith(response.headers().getContentType())) { |
196 | 195 | try { |
197 | | - JsonNode jsonBodyContent = OBJECT_MAPPER.readValue(responseBody, JsonNode.class); |
198 | | - |
| 196 | + JsonNode jsonBodyContent = jsonMapper.readValue(responseBody, JsonNode.class); |
199 | 197 | removeJsonAttributes(jsonBodyContent, immutableFieldList, deleteRecursively); |
200 | | - |
201 | | - responseBody = OBJECT_MAPPER.writeValueAsString(jsonBodyContent); |
| 198 | + responseBody = jsonMapper.writeValueAsString(jsonBodyContent); |
202 | 199 | } |
203 | | - catch (JsonProcessingException exception) { |
| 200 | + catch (JacksonException exception) { |
204 | 201 | throw new IllegalStateException("Failed to process JSON of response body.", exception); |
205 | 202 | } |
206 | 203 | } |
|
0 commit comments