@Test
    public void testSerializeDeserializeWithAnnotations() throws IOException {
        Document doc = new Document(docType, "id:ns:dokk::bar");

        doc.setFieldValue("age", (byte)123);
        doc.setFieldValue("story", getAnnotatedString());
        doc.setFieldValue("date", 13829297);
        doc.setFieldValue("friend", 2384L);

        GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
        DocumentSerializer serializer = DocumentSerializerFactory.createHead(buffer);
        serializer.write(doc);
        buffer.flip();

        FileOutputStream fos = new FileOutputStream("src/tests/data/serializejavawithannotations.dat");
        fos.write(buffer.array(), 0, buffer.limit());
        fos.close();

        DocumentDeserializer deserializer = DocumentDeserializerFactory.createHead(man, buffer);
        Document doc2 = new Document(deserializer);

        assertEquals(doc, doc2);
        assertNotSame(doc, doc2);
    }
Tests serialization of all versions.
<p/>
This test tests serialization and deserialization of documents of all
supported types.
<p/>
Serialization is only supported in newest format. Deserialization should work
for all formats supported, but only the part that makes sense in the new
format. Thus, if new format deprecates a datatype, that datatype, when
serializing old versions, must either just be dropped or converted.
<p/>
Thus, we create document type programmatically, because all old versions need
to make sense with current config.
<p/>
When we create a document programmatically. This is serialized into current
version files. When altering the format, after the alteration, copy the
current version files to a specific version file and add those to list of
files this test checks.
<p/>
When adding new fields to the documents, use the version tagged with each
file to ignore these field for old types.

@author arnej27959
document/src/test/java/com/yahoo/document/DocumentSerializationTestCase.java