-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Simplify RemoveJsonAttributesResponseBodyGatewayFilterFactory #3776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify RemoveJsonAttributesResponseBodyGatewayFilterFactory #3776
Conversation
} | ||
catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
return Mono.error(new IllegalStateException("Failed to process JSON of response body.", e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
The caller wraps the error with
Mono.error()
to preserve the reactive pipeline and allow proper error handling. -
The exception type has been explicitly changed to
IllegalStateException
.
private void removeJsonAttributes(JsonNode jsonNode, List<String> fieldNames, boolean deleteRecursively) { | ||
if (jsonNode instanceof ObjectNode objectNode) { | ||
objectNode.remove(fieldNames); | ||
} | ||
if (jsonBodyContent instanceof ObjectNode) { | ||
((ObjectNode) jsonBodyContent).remove(fieldsToRemove); | ||
if (deleteRecursively) { | ||
jsonNode.forEach(childNode -> removeJsonAttributes(childNode, fieldNames, true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the logic to recursively remove JSON nodes without type distinction, allowing recursive calls regardless of node type.
Can you submit this against the 4.1.x branch? |
…actory Signed-off-by: raccoonback <[email protected]>
c991ecd
to
2458503
Compare
@ryanjbaxter I've changed the target to the 4.1.x branch. |
Summary
This pull request refactors the filter responsible for removing fields from JSON-formatted response bodies.
Simplified the filtering logic for better readability, and improved internal method structure and naming.
Changes
Mono.error()
.This allows the calling side to handle errors explicitly within the Reactive pipeline.
The change does not affect backward compatibility.
IllegalStateException
.I think using a more specific exception type would improve clarity.
Let me know if further adjustments are needed.