diff --git a/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java b/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java index 55fe7323b..bfce2844d 100644 --- a/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java +++ b/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java @@ -260,7 +260,9 @@ public BodyFilter bodyFilter() { public BodyFilter jsonBodyFieldsFilter() { final LogbookProperties.Obfuscate obfuscate = properties.getObfuscate(); final List jsonBodyFields = obfuscate.getJsonBodyFields(); - + if (jsonBodyFields.isEmpty()) { + return BodyFilter.none(); + } return new JacksonJsonFieldBodyFilter(jsonBodyFields, obfuscate.getReplacement()); } diff --git a/logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java b/logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java new file mode 100644 index 000000000..956e57718 --- /dev/null +++ b/logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java @@ -0,0 +1,25 @@ +package org.zalando.logbook.autoconfigure; + +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.zalando.logbook.BodyFilter; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +@LogbookTest +class ObfuscateBodyDefaultTest { + + @Autowired + @Qualifier("jsonBodyFieldsFilter") + private BodyFilter jsonBodyFieldsFilter; + + @Test + void shouldNotFilterJsonBodiesIfEmptyObfuscateJsonBodyFieldNames() throws IOException, JSONException { + assertThat(jsonBodyFieldsFilter).isSameAs(BodyFilter.none()); + } + +}