@Test
    public void testUnknownFieldsDeserialization() {
        DocumentTypeManager docTypeManasjer = new DocumentTypeManager();

        GrowableByteBuffer buf = new GrowableByteBuffer();

        {
            DocumentType typeWithDinner = new DocumentType("elvis");
            typeWithDinner.addField("breakfast", DataType.STRING);
            typeWithDinner.addField("lunch", DataType.INT);
            typeWithDinner.addField("dinner", DataType.DOUBLE);
            docTypeManasjer.registerDocumentType(typeWithDinner);

            Document docWithDinner = new Document(typeWithDinner, "id:ns:elvis::has:left:the:building");
            docWithDinner.setFieldValue("breakfast", "peanut butter");
            docWithDinner.setFieldValue("lunch", 14);
            docWithDinner.setFieldValue("dinner", 5.43d);

            docWithDinner.serialize(buf);
            buf.flip();

            docTypeManasjer.internalClear();
        }

        {
            DocumentType typeWithoutDinner = new DocumentType("elvis");
            typeWithoutDinner.addField("breakfast", DataType.STRING);
            typeWithoutDinner.addField("lunch", DataType.INT);
            //no dinner
            docTypeManasjer.registerDocumentType(typeWithoutDinner);

            Document docWithoutDinner = docTypeManasjer.createDocument(buf);

            assertEquals(new StringFieldValue("peanut butter"), docWithoutDinner.getFieldValue("breakfast"));
            assertEquals(new IntegerFieldValue(14), docWithoutDinner.getFieldValue("lunch"));
            assertNull(docWithoutDinner.getFieldValue("dinner"));
        }
    }
Test for Document and all its features, including (de)serialization.

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