Skip to content

Commit f08e436

Browse files
fix: include furniture field in DoclingDocument (#387)
1 parent 4be3369 commit f08e436

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

docling-core/src/main/java/ai/docling/core/DoclingDocument.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class DoclingDocument {
4444
@JsonProperty("body")
4545
private GroupItem body;
4646

47+
@JsonProperty("furniture")
48+
@Nullable
49+
private GroupItem furniture;
50+
4751
@JsonProperty("groups")
4852
@JsonSetter(nulls = Nulls.AS_EMPTY)
4953
@lombok.Singular

docling-core/src/test/java/ai/docling/core/DoclingDocumentTests.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
import org.junit.jupiter.api.Test;
66

7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
import ai.docling.core.DoclingDocument.ContentLayer;
710
import ai.docling.core.DoclingDocument.DocItemLabel;
11+
import ai.docling.core.DoclingDocument.GroupItem;
12+
import ai.docling.core.DoclingDocument.GroupLabel;
813
import ai.docling.core.DoclingDocument.TitleItem;
914

1015
/**
@@ -35,4 +40,49 @@ void shouldBuildDocumentWithProperties() {
3540
assertThat(titleItem.getText()).isEqualTo("Docling Rocks!");
3641
}
3742

43+
@Test
44+
void shouldSerializeFurnitureField() throws Exception {
45+
ObjectMapper mapper = new ObjectMapper();
46+
GroupItem furniture = GroupItem.builder()
47+
.selfRef("#/furniture")
48+
.contentLayer(ContentLayer.FURNITURE)
49+
.label(GroupLabel.UNSPECIFIED)
50+
.name("_root_")
51+
.build();
52+
53+
DoclingDocument document = DoclingDocument.builder()
54+
.name("test-document")
55+
.furniture(furniture)
56+
.build();
57+
58+
String json = mapper.writeValueAsString(document);
59+
60+
assertThat(json).contains("\"furniture\"");
61+
assertThat(json).contains("\"content_layer\":\"furniture\"");
62+
}
63+
64+
@Test
65+
void shouldDeserializeFurnitureField() throws Exception {
66+
ObjectMapper mapper = new ObjectMapper();
67+
String json = """
68+
{
69+
"name": "test-document",
70+
"furniture": {
71+
"self_ref": "#/furniture",
72+
"children": [],
73+
"content_layer": "furniture",
74+
"name": "_root_",
75+
"label": "unspecified"
76+
}
77+
}
78+
""";
79+
80+
DoclingDocument document = mapper.readValue(json, DoclingDocument.class);
81+
82+
assertThat(document.getFurniture()).isNotNull();
83+
assertThat(document.getFurniture().getSelfRef()).isEqualTo("#/furniture");
84+
assertThat(document.getFurniture().getContentLayer()).isEqualTo(ContentLayer.FURNITURE);
85+
assertThat(document.getFurniture().getLabel()).isEqualTo(GroupLabel.UNSPECIFIED);
86+
}
87+
3888
}

0 commit comments

Comments
 (0)