|
4 | 4 |
|
5 | 5 | import org.junit.jupiter.api.Test; |
6 | 6 |
|
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | + |
| 9 | +import ai.docling.core.DoclingDocument.ContentLayer; |
7 | 10 | import ai.docling.core.DoclingDocument.DocItemLabel; |
| 11 | +import ai.docling.core.DoclingDocument.GroupItem; |
| 12 | +import ai.docling.core.DoclingDocument.GroupLabel; |
8 | 13 | import ai.docling.core.DoclingDocument.TitleItem; |
9 | 14 |
|
10 | 15 | /** |
@@ -35,4 +40,49 @@ void shouldBuildDocumentWithProperties() { |
35 | 40 | assertThat(titleItem.getText()).isEqualTo("Docling Rocks!"); |
36 | 41 | } |
37 | 42 |
|
| 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 | + |
38 | 88 | } |
0 commit comments