fix(core): preserve empty-string text/orig fields during serialization#603
Conversation
Add @JsonInclude(NON_NULL) on text and orig fields in all DoclingDocument inner classes that had the class-level @JsonInclude(NON_EMPTY) causing empty strings to be silently dropped during serialization. Affected classes: TitleItem, SectionHeaderItem, FieldHeadingItem, ListItem, CodeItem, FormulaItem, TextItem, FieldValueItem, EntityMention, SummaryMetaField, CodeMetaField, DescriptionMetaField, TableCell, GraphCell. Add tests for empty-string text/orig serialization and roundtrip. Closes #598
edeandrea
left a comment
There was a problem hiding this comment.
- Please adhere to semantic commits
- I don't think this actually solves the issue since
DoclingDocumentalready has@JsonInclude(NON_EMPTY)at the class level. I don't think this addresses the user's problem.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
The non-semantic "Initial plan" commit was empty (no file changes) and has been dropped via rebase (fb72beb is now the only commit on the branch). On whether the fix works: field-level |
|
@copilot what if we flip the logic? During deserialization, we should consider an empty string as |
…ation Add custom setter methods to the Lombok Builder inner classes of the 14 affected DoclingDocument classes so that any empty-string value provided for 'text' or 'orig' is converted to null before the object is built. The class-level @JsonInclude(NON_EMPTY) then naturally omits these null fields during serialization, keeping the wire format consistent. Affected classes: TitleItem, SectionHeaderItem, FieldHeadingItem, ListItem, CodeItem, FormulaItem, TextItem, FieldValueItem, EntityMention, SummaryMetaField, CodeMetaField, DescriptionMetaField, TableCell, GraphCell. Also add @nullable to all text/orig fields that lacked it (package is @NullMarked; these fields can legitimately be null after normalization). Closes #598 Signed-off-by: copilot-swe-agent[bot] <copilot-swe-agent@github.com>
Done in 2224e05. Custom I also added |
|
@copilot are you sure thats the correct fix? Can't we instead get jackson to treat |
…rig to null Replace 14 custom builder setter methods with Jackson-native EmptyStringToNullJackson2Deserializer / EmptyStringToNullJackson3Deserializer inner classes. The affected text and orig fields are annotated with @JsonDeserialize(using = ...) for both Jackson 2 and 3, so empty strings in JSON are normalized to null during deserialization. Serialization continues to omit both null and empty-string values via the class-level @JsonInclude(NON_EMPTY).
Done in the latest commit. The approach is now:
|
@JsonInclude(NON_EMPTY)at the class level onDoclingDocumentinner classes silently dropsStringfields with value""during serialization — losing meaningful data such as"text": ""onFormulaItemwhendo_formula_enrichment=false.Changes
DoclingDocument: Add@JsonInclude(NON_NULL)at the field level on alltextandorigfields in the 14 affected inner classes (TitleItem,SectionHeaderItem,FieldHeadingItem,ListItem,CodeItem,FormulaItem,TextItem,FieldValueItem,EntityMention,SummaryMetaField,CodeMetaField,DescriptionMetaField,TableCell,GraphCell). Field-levelNON_NULLoverrides the class-levelNON_EMPTYfor just these fields, so empty strings are preserved while empty collections/maps are still suppressed.DoclingDocumentTests: Two new tests — one asserting that a builtFormulaItemwith emptytext/origserializes those fields, and one verifying the full deserialize → serialize round-trip preserves empty strings.