diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java index 02915681..dc758224 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java @@ -465,11 +465,22 @@ public class GatewayFilterSpec extends UriSpec { } } + /** + * A filter that can be used to modify the response body. By default, this only + * removes root attributes. + * @param attributes list of attributes to remove. + * @return a {@link GatewayFilterSpec} that can be used to apply additional filters + */ + public GatewayFilterSpec removeJsonAttributes(String... attributes) { + return removeJsonAttributes(false, attributes); + + } + /** * A filter that can be used to modify the response body. - * @param attributes list of attributes to remove separated by commas, an optional - * last parameter from the list can be a boolean to remove the attributes just at root - * level (false) o recursively (true) + * @param attributes list of attributes to remove. + * @param deleteRecursively if true, all attributes regardless of nesting will be + * removed. * @return a {@link GatewayFilterSpec} that can be used to apply additional filters */ public GatewayFilterSpec removeJsonAttributes(boolean deleteRecursively, String... attributes) { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/config/conditional/DisableBuiltInFiltersTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/config/conditional/DisableBuiltInFiltersTests.java index 77ddb901..43cee407 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/config/conditional/DisableBuiltInFiltersTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/config/conditional/DisableBuiltInFiltersTests.java @@ -90,6 +90,7 @@ public class DisableBuiltInFiltersTests { "spring.cloud.gateway.filter.prefix-path.enabled=false", "spring.cloud.gateway.filter.preserve-host-header.enabled=false", "spring.cloud.gateway.filter.redirect-to.enabled=false", + "spring.cloud.gateway.filter.remove-json-attributes-response-body.enabled=false", "spring.cloud.gateway.filter.remove-request-header.enabled=false", "spring.cloud.gateway.filter.remove-request-parameter.enabled=false", "spring.cloud.gateway.filter.remove-response-header.enabled=false", diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveJsonAttributesResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveJsonAttributesResponseBodyGatewayFilterFactoryTests.java index ad2a5b41..84db78fd 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveJsonAttributesResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveJsonAttributesResponseBodyGatewayFilterFactoryTests.java @@ -110,7 +110,7 @@ public class RemoveJsonAttributesResponseBodyGatewayFilterFactoryTests extends B .filters(f -> f.removeJsonAttributes(true, "foo")).uri(uri)) .route("remove_json_attributes_no_matches_java_test", r -> r.path("/post").and().host("{sub}.removejsonattributesnomatches.org") - .filters(f -> f.removeJsonAttributes(false, "test")).uri(uri)) + .filters(f -> f.removeJsonAttributes("test")).uri(uri)) .build(); }