@Test
  public void testHeterogeneousObjects() {
    String[] fields = new String[] {"s", "i", "l", "d", "f", "s2", "missing"};
    HeterogeneousLuceneSerializer mapper = new HeterogeneousLuceneSerializer();

    Type1 t1 = new Type1("a", 1, 2L, 3.0, 4.0f);

    Document doc1 = SerializerTestHelper.invokeSerializer(mapper, t1, fields);

    assertEquals(5, doc1.getFields().size());
    assertEquals("a", doc1.getField("s").stringValue());
    assertEquals(1, doc1.getField("i").numericValue());
    assertEquals(2L, doc1.getField("l").numericValue());
    assertEquals(3.0, doc1.getField("d").numericValue());
    assertEquals(4.0f, doc1.getField("f").numericValue());

    Type2 t2 = new Type2("a", 1, 2L, 3.0, 4.0f, "b");

    Document doc2 = SerializerTestHelper.invokeSerializer(mapper, t2, fields);

    assertEquals(6, doc2.getFields().size());
    assertEquals("a", doc2.getField("s").stringValue());
    assertEquals("b", doc2.getField("s2").stringValue());
    assertEquals(1, doc2.getField("i").numericValue());
    assertEquals(2L, doc2.getField("l").numericValue());
    assertEquals(3.0, doc2.getField("d").numericValue());
    assertEquals(4.0f, doc2.getField("f").numericValue());

    PdxInstance pdxInstance = mock(PdxInstance.class);

    when(pdxInstance.hasField("s")).thenReturn(true);
    when(pdxInstance.hasField("i")).thenReturn(true);
    when(pdxInstance.getField("s")).thenReturn("a");
    when(pdxInstance.getField("i")).thenReturn(5);

    Document doc3 = SerializerTestHelper.invokeSerializer(mapper, pdxInstance, fields);

    assertEquals(2, doc3.getFields().size());
    assertEquals("a", doc3.getField("s").stringValue());
    assertEquals(5, doc3.getField("i").numericValue());
  }
Test that the mapper can handle a mix of different object types.
geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializerJUnitTest.java