@Test
    public void testGenerateSerializedFile() throws IOException {

        docMan = setUpCppDocType();
        Document doc = new Document(docMan.getDocumentType("serializetest"),
                                    new DocumentId("id:ns:serializetest::http://test.doc.id/"));

        Document docindoc = new Document(docMan.getDocumentType("docindoc"),
                                         new DocumentId("id:ns:docindoc::http://doc.in.doc/"));
        docindoc.setFieldValue("stringindocfield", "Elvis is dead");
        doc.setFieldValue("docfield", docindoc);

        Array<FloatFieldValue> l = new Array<>(doc.getField("arrayoffloatfield").getDataType());
        l.add(new FloatFieldValue((float)1.0));
        l.add(new FloatFieldValue((float)2.0));
        doc.setFieldValue("arrayoffloatfield", l);

        WeightedSet<StringFieldValue>
                wset = new WeightedSet<>(doc.getDataType().getField("wsfield").getDataType());
        wset.put(new StringFieldValue("Weighted 0"), 50);
        wset.put(new StringFieldValue("Weighted 1"), 199);
        doc.setFieldValue("wsfield", wset);

        MapFieldValue<StringFieldValue, StringFieldValue> map =
                new MapFieldValue<>((MapDataType)doc.getDataType().getField("mapfield").getDataType());
        map.put(new StringFieldValue("foo1"), new StringFieldValue("bar1"));
        map.put(new StringFieldValue("foo2"), new StringFieldValue("bar2"));
        doc.setFieldValue("mapfield", map);

        doc.setFieldValue("boolfield", new BoolFieldValue(true));
        doc.setFieldValue("bytefield", new ByteFieldValue((byte)254));
        doc.setFieldValue("rawfield", new Raw(ByteBuffer.wrap("RAW DATA".getBytes())));
        doc.setFieldValue("intfield", new IntegerFieldValue(5));
        doc.setFieldValue("floatfield", new FloatFieldValue(-9.23f));
        doc.setFieldValue("stringfield", new StringFieldValue("This is a string."));
        doc.setFieldValue("longfield", new LongFieldValue(398420092938472983L));
        doc.setFieldValue("doublefield", new DoubleFieldValue(98374532.398820d));
        doc.setFieldValue("urifield", new StringFieldValue("http://this.is.a.test/"));

        int size = doc.getSerializedSize();
        GrowableByteBuffer buf = new GrowableByteBuffer(size, 2.0f);

        doc.serialize(buf);
        assertEquals(size, buf.position());

        buf.position(0);

        FileOutputStream fos = new FileOutputStream("src/tests/data/serializejava.dat");
        fos.write(buf.array(), 0, size);
        fos.close();
    }
Test for Document and all its features, including (de)serialization.

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