@Test
    public void testEmptyStringsSerialization() {
        docMan = new DocumentTypeManager();
        DocumentType docType = new DocumentType("emptystrings");
        docType.addField(new Field("emptystring", DataType.STRING));
        docType.addField(new Field("nullstring", DataType.STRING));
        docType.addField(new Field("spacestring", DataType.STRING));
        docType.addField(new Field("astring", DataType.STRING));
        docMan.registerDocumentType(docType);

        GrowableByteBuffer grbuf = new GrowableByteBuffer();
        {
            Document doc = new Document(docType, new DocumentId("id:ns:emptystrings::"));

            doc.setFieldValue("emptystring", "");
            doc.removeFieldValue("nullstring");
            doc.setFieldValue("spacestring", " ");
            doc.setFieldValue("astring", "a");
            assertEquals(new StringFieldValue(""), doc.getFieldValue("emptystring"));
            assertNull(doc.getFieldValue("nullstring"));
            assertEquals(new StringFieldValue(" "), doc.getFieldValue("spacestring"));
            assertEquals(new StringFieldValue("a"), doc.getFieldValue("astring"));

            doc.getSerializedSize();
            doc.serialize(grbuf);

            grbuf.flip();
        }
        {
            Document doc2 = docMan.createDocument(grbuf);

            assertEquals(new StringFieldValue(""), doc2.getFieldValue("emptystring"));
            assertNull(doc2.getFieldValue("nullstring"));
            assertEquals(new StringFieldValue(" "), doc2.getFieldValue("spacestring"));
            assertEquals(new StringFieldValue("a"), doc2.getFieldValue("astring"));

        }
    }
Test for Document and all its features, including (de)serialization.

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