You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After I upgraded Logbook version to 3.9.0 I noticed that there is JacksonJsonFieldBodyFilter bean in LogbookAutoConfiguration class. It works after PrettyPrintingJsonBodyFilter and compresses json. I tried various ways to create BodyFilters bean, but don't find good one.
Context
I didn't find in the documentation how to achieve pretty printing of JSON using Logbook. It would be very useful for our cozy community.
Possible Implementation
The only but bad solution I found is just copy JacksonJsonFieldBodyFilter bean from LogbookAutoConfiguration class to my Logbook @Configuration class before PrettyPrintingJsonBodyFilter bean. So PrettyPrintingJsonBodyFilter injects into the Logbook constructor at the end of bodyFIlters list and works at the end of the BodyFilter chain.
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;
importorg.zalando.logbook.BodyFilter;
importorg.zalando.logbook.HttpLogWriter;
importorg.zalando.logbook.autoconfigure.LogbookProperties;
importorg.zalando.logbook.json.JacksonJsonFieldBodyFilter;
importorg.zalando.logbook.json.PrettyPrintingJsonBodyFilter;
importjava.util.List;
@ConfigurationpublicclassLogbookConfig {
@BeanpublicHttpLogWriterwriter(CustomLogbookLoggerPropertiesproperties) {
returnnewCustomHttpLogWriter(properties);
}
/** * It's just a copied implementation of {@link org.zalando.logbook.autoconfigure.LogbookAutoConfiguration#jsonBodyFieldsFilter()}. * We need it only to inject JacksonJsonFieldBodyFilter in List<BodyFilter> bodyFilters to * {@link org.zalando.logbook.autoconfigure.LogbookAutoConfiguration#logbook} before * {@link PrettyPrintingJsonBodyFilter}. So PrettyPrintingJsonBodyFilter works at the end of the filter chain */@BeanpublicJacksonJsonFieldBodyFilterjsonBodyFieldsFilter(LogbookPropertiesproperties) {
finalLogbookProperties.Obfuscateobfuscate = properties.getObfuscate();
finalList<String> jsonBodyFields = obfuscate.getJsonBodyFields();
returnnewJacksonJsonFieldBodyFilter(jsonBodyFields, obfuscate.getReplacement());
}
@BeanpublicBodyFilterprettyPrintingJsonBodyFilter() {
returnnewPrettyPrintingJsonBodyFilter();
}
}
How to pretty-print JSON with different
BodyFilter
s?Detailed Description
Using Logbook version 2.14.0 I configured
BodyFIlter
like this:After I upgraded Logbook version to 3.9.0 I noticed that there is
JacksonJsonFieldBodyFilter
bean inLogbookAutoConfiguration
class. It works afterPrettyPrintingJsonBodyFilter
and compresses json. I tried various ways to createBodyFilter
s bean, but don't find good one.Context
I didn't find in the documentation how to achieve pretty printing of JSON using Logbook. It would be very useful for our cozy community.
Possible Implementation
The only but bad solution I found is just copy
JacksonJsonFieldBodyFilter
bean fromLogbookAutoConfiguration
class to my Logbook@Configuration
class beforePrettyPrintingJsonBodyFilter
bean. SoPrettyPrintingJsonBodyFilter
injects into the Logbook constructor at the end of bodyFIlters list and works at the end of theBodyFilter
chain.Your Environment
Thanks in advance
The text was updated successfully, but these errors were encountered: