• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zalando / logbook / 5763
97%
master: 100%

Build:
Build:
LAST BUILD BRANCH: main
DEFAULT BRANCH: master
Ran 27 Jul 2026 11:14AM UTC
Jobs 1
Files 236
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

27 Jul 2026 11:09AM UTC coverage: 96.601% (-0.3%) from 96.858%
5763

push

github

web-flow
Fix JSON formatter embedding non-JSON body as raw value (#2326)

* Fix JSON formatter embedding non-JSON body as raw value

When a request body has a JSON content-type header but contains
non-JSON content (e.g. Base64-encoded ciphertext, binary data, or
truncated/malformed JSON), the formatters were embedding the raw
body directly using @JsonRawValue / writeRawValue(), producing
malformed JSON log output that breaks Logstash and Elasticsearch
ingestion.

Fix applied to all four formatters:
- JsonHttpLogFormatter (Jackson 3)
- FastJsonHttpLogFormatter (Jackson 3)
- JsonHttpLogFormatterJackson2 (Jackson 2)
- FastJsonHttpLogFormatterJackson2 (Jackson 2)

Each formatter now uses a two-stage validation approach:
1. Fast path: check first non-whitespace character against valid
   JSON start characters ({ [ " digit - t f n). Obvious non-JSON
   content like ciphertext is rejected immediately at zero parse cost.
2. Slow path: only if the fast check passes, attempt full JSON
   validation via readTree(). If parsing fails, fall back to logging
   the body as a safely quoted plain string.

This ensures the overall JSON log structure is always valid while
preserving existing behaviour for valid JSON bodies and keeping
the performance impact minimal for the common case.

Also resolves the long-standing TODO comment in
JsonHttpLogFormatterJackson2.prepareBody() regarding missing
JSON validation.

Test assertions in WriteBodyMaxSizeTest updated to reflect the
corrected behaviour: truncated bodies (produced by BodyMaxSizeFilter)
are now correctly logged as quoted strings rather than raw invalid JSON.

Fixes #2318

* Fix JSON formatter embedding non-JSON body as raw value

Extract shared JsonUtil validation helper per module. Add opt-in
validateJsonBody flag (default: false) to all four formatters and
wire it through LogbookProperties for Spring Boot users.

Fixes #2318

* Rename JsonUtil to JsonUtilJackson2 to fix duplicate-finder plugin

* Address review feedback: p... (continued)

874 of 922 branches covered (94.79%)

70 of 83 new or added lines in 7 files covered. (84.34%)

4007 of 4148 relevant lines covered (96.6%)

0.97 hits per line

Uncovered Changes

Lines Coverage ∆ File
7
78.33
-7.38% logbook-json/src/main/java/org/zalando/logbook/json/FastJsonHttpLogFormatter.java
6
88.0
-12.0% logbook-json-jackson2/src/main/java/org/zalando/logbook/json/FastJsonHttpLogFormatterJackson2.java
Jobs
ID Job ID Ran Files Coverage
1 5763.1 27 Jul 2026 11:14AM UTC 236
96.6
GitHub Action Run
Source Files on build 5763
  • Tree
  • List 236
  • Changed 6
  • Source Changed 6
  • Coverage Changed 5
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • Github Actions Build #5763
  • 310b6d91 on github
  • Prev Build on main (#5762)
  • Next Build on main (#5764)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc