`@JsonInclude(NON_EMPTY)` makes DoclingDocument serialization lossy
Serve keeps "text": "" on formula items (do_formula_enrichment=false). The Java DoclingDocument still has text as "", but serialization drops it:
DoclingDocument doc = response.getDocument().getJsonContent();
// doc still has text == ""
byte[] bytes = jsonMapper.writeValueAsBytes(doc); // "text" omitted in JSON
Include.ALWAYS on the mapper does not help — class-level @JsonInclude(NON_EMPTY) wins. No raw json_content accessor either.
Wanted: lossless serialize, or raw json_content bytes/JsonNode.
Related: docling#3780, docling-java#386
@all-contributors add @rkudryashov for issue
@edeandrea
I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.
@all-contributors add @rkudryashov for bug
Hi @rkudryashov I'm not sure I fully understand the issue? Could you explain a bit more?
Are you saying that "on the wire" the field is present in the json but with an empty value, but after deserialization the field is null?
@edeandrea Not quite — after deserialization the Java field is still "" (not null). The loss happens on the way back out:
- Serve wire JSON:
"text": "" DoclingDocumentin memory:text == ""jsonMapper.writeValueAsBytes(doc)→textkey absent (class-level@JsonInclude(NON_EMPTY))
Setting Include.ALWAYS on the JsonMapper/ObjectMapper does not help, because @JsonInclude(NON_EMPTY) on the model class takes precedence.
So with the public API there is no straightforward way to persist a lossless DoclingDocument JSON that keeps "text": "" — writeValueAsBytes(doc) will drop those fields.
Let me ask a question - do you consider an empty string different from null?
Yes. For us "" and null/absent are different.
text: "" is valid DoclingDocument state (e.g. formulas with enrichment off). After Jackson serialize + S3, empty strings are dropped → text is missing.
When we rehydrate that JSON we hit two failures:
- Schema validation — we validate against the official
DoclingDocumentJSON Schema (DoclingDocument.json). Missingtextfails validation;"text": ""passes. - Chunking — hybrid /
json_doclingchunking then fails on the same invalid document.
Let me check with the docling team on the intention (i.e. do they differentiate between empty/null/absent). I've always been in the camp that "" == null/absent, but if the docling team specifically treats it differently then we should respect that here. If they don't have any guidance or they don't care, then I'm not sure you can make that assumption on your side.
@rkudryashov thanks for the detailed report, and for tracking the root cause back here from docling-project/docling#3780 and docling-project/docling#4107.
The fix is in #723. The cause was what you described: the inner classes of DoclingDocument carry a class-level @JsonInclude(NON_EMPTY), which drops "" on write, and a mapper-level inclusion setting doesn't override it.
On whether "" is different from null or absent: docling hasn't answered that directly, but the DoclingDocument JSON schema settles the part that matters here. text and orig are required strings, so "" is valid and a missing field is not. #723 keeps "" as "" by adding a field-level @JsonInclude(NON_NULL) to the 23 required text/orig fields. Empty lists are still omitted, and a field that is really unset (null) is still left out.
This issue will close automatically when #723 merges.
🎉 This issue has been resolved in v0.7.0 (Release Notes)