@Test
    public void testSerializeDeserialize() throws IOException {
        setUpSertestDocType();
        Document doc = getSertestDocument();

        GrowableByteBuffer data = new GrowableByteBuffer();
        doc.serialize(data);
        int size = doc.getSerializedSize();

        assertEquals(size, data.position());

        data.flip();

        try (FileOutputStream fos = new FileOutputStream("src/test/files/testser.dat")) {
            fos.write(data.array(), 0, data.remaining());
        }

        Document doc2 = docMan.createDocument(data);

        assertEquals(doc.getFieldValue("myboolfield"), doc2.getFieldValue("myboolfield"));
        assertEquals(doc.getFieldValue("mailid"), doc2.getFieldValue("mailid"));
        assertEquals(doc.getFieldValue("date"), doc2.getFieldValue("date"));
        assertEquals(doc.getFieldValue("from"), doc2.getFieldValue("from"));
        assertEquals(doc.getFieldValue("to"), doc2.getFieldValue("to"));
        assertEquals(doc.getFieldValue("subject"), doc2.getFieldValue("subject"));
        assertEquals(doc.getFieldValue("body"), doc2.getFieldValue("body"));
        assertEquals(doc.getFieldValue("attachmentcount"), doc2.getFieldValue("attachmentcount"));
        assertEquals(doc.getFieldValue("attachments"), doc2.getFieldValue("attachments"));
        byte[] docRawBytes = ((Raw)doc.getFieldValue("rawfield")).getByteBuffer().array();
        byte[] doc2RawBytes = ((Raw)doc2.getFieldValue("rawfield")).getByteBuffer().array();
        assertEquals(docRawBytes.length, doc2RawBytes.length);
        for (int i = 0; i < docRawBytes.length; i++) {
            assertEquals(docRawBytes[i], doc2RawBytes[i]);
        }
        assertEquals(doc.getFieldValue("weightedfield"), doc2.getFieldValue("weightedfield"));
        assertEquals(doc.getFieldValue("mapfield"), doc2.getFieldValue("mapfield"));
    }
Test for Document and all its features, including (de)serialization.

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