SimpleMongoDBSerializer extends SimpleJsonSerializer { @Nonnull public static SimpleMongoDBSerializer getInstance() { return INSTANCE; } private  SimpleMongoDBSerializer(); @Nonnull static SimpleMongoDBSerializer getInstance();  }
@Test public void testPerson() { LOG.info("testPerson"); final DateTime now = UTCTime.now(); final Woman jane = new Woman("jane", now, null, Gender.FEMALE, Collections.<Person>emptyList(), true, Collections.<Set<Person>>emptyList(), new Object[0]); final Person joe = new Person("joe", now, jane, Gender.MALE, Collections.<Person>emptyList(), new Object[0]); final Person jim = new Person("jim", now, jane, Gender.MALE, Collections.<Person>emptyList(), new Object[0]); final Person mary = new Woman("mary", now, jane, Gender.MALE, Immutables.listOf(joe, jim), false, Collections.singletonList(Immutables.setOf(jane, joe)), new Object[]{"A String", joe}); final Object dbValue = SimpleMongoDBSerializer.getInstance().serialize(mary); LOG.info("Serialized: " + SimpleJsonSerializer.getInstance().toString(mary)); Assert.assertTrue(dbValue instanceof DBObject); final Object person = SimpleMongoDBSerializer.getInstance().deserialize(dbValue); LOG.info("Deserialized: " + SimpleJsonSerializer.getInstance().toString(person)); Assert.assertTrue(person instanceof Woman); final Woman woman = (Woman) person; Assert.assertNotNull(woman.getFavorites()); Assert.assertEquals(1, woman.getFavorites().size()); Assert.assertEquals(2, woman.getFavorites().get(0).size()); Assert.assertSame(Woman.class, woman.getFavorites().get(0).iterator().next().getClass()); Assert.assertNotNull(woman.getThings()); Assert.assertEquals(2, woman.getThings().length); Assert.assertEquals("A String", woman.getThings()[0]); Assert.assertSame(Person.class, woman.getThings()[1].getClass()); }