Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class DoclingDocument {
@JsonProperty("body")
private GroupItem body;

@JsonProperty("furniture")
@Nullable
private GroupItem furniture;

@JsonProperty("groups")
@JsonSetter(nulls = Nulls.AS_EMPTY)
@lombok.Singular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import ai.docling.core.DoclingDocument.ContentLayer;
import ai.docling.core.DoclingDocument.DocItemLabel;
import ai.docling.core.DoclingDocument.GroupItem;
import ai.docling.core.DoclingDocument.GroupLabel;
import ai.docling.core.DoclingDocument.TitleItem;

/**
Expand Down Expand Up @@ -35,4 +40,49 @@ void shouldBuildDocumentWithProperties() {
assertThat(titleItem.getText()).isEqualTo("Docling Rocks!");
}

@Test
void shouldSerializeFurnitureField() throws Exception {
ObjectMapper mapper = new ObjectMapper();
GroupItem furniture = GroupItem.builder()
.selfRef("#/furniture")
.contentLayer(ContentLayer.FURNITURE)
.label(GroupLabel.UNSPECIFIED)
.name("_root_")
.build();

DoclingDocument document = DoclingDocument.builder()
.name("test-document")
.furniture(furniture)
.build();

String json = mapper.writeValueAsString(document);

assertThat(json).contains("\"furniture\"");
assertThat(json).contains("\"content_layer\":\"furniture\"");
}

@Test
void shouldDeserializeFurnitureField() throws Exception {
ObjectMapper mapper = new ObjectMapper();
String json = """
{
"name": "test-document",
"furniture": {
"self_ref": "#/furniture",
"children": [],
"content_layer": "furniture",
"name": "_root_",
"label": "unspecified"
}
}
""";

DoclingDocument document = mapper.readValue(json, DoclingDocument.class);

assertThat(document.getFurniture()).isNotNull();
assertThat(document.getFurniture().getSelfRef()).isEqualTo("#/furniture");
assertThat(document.getFurniture().getContentLayer()).isEqualTo(ContentLayer.FURNITURE);
assertThat(document.getFurniture().getLabel()).isEqualTo(GroupLabel.UNSPECIFIED);
}

}