@Test
    public void testSerializationToJson() throws Exception {
        setUpSertestDocType();
        Document doc = getSertestDocument();
        String json = doc.toJson();
        Map<String, Object> parsed = Jackson.mapper().readValue(json, new TypeReference<>() {});
        assertEquals(parsed.get("id"), "id:ns:sertest::foobar");
        assertTrue(parsed.get("fields") instanceof Map);
        Object fieldMap = parsed.get("fields");
        if (fieldMap instanceof Map<?, ?> fields) {
            assertEquals(fields.get("mailid"), "emailfromalicetobob");
            assertEquals(fields.get("date"), -2013512400);
            assertTrue(fields.get("docindoc") instanceof Map);
            assertTrue(fields.keySet().containsAll(List.of("mailid", "date", "attachmentcount", "rawfield", "weightedfield", "docindoc", "mapfield", "myboolfield")));
        }
    }
Test for Document and all its features, including (de)serialization.

@author Thomas Gundersen
@author bratseth
document/src/test/java/com/yahoo/document/DocumentTestCase.java