@Test public void testLinkedHashSet() throws Exception { LinkedHashSet<I> src = LinkedHashSet.of(new B()); String json = MAPPER.writeValueAsString(new LinkedHashSetPojo().setValue(src)); Assert.assertEquals(json, "{\"value\":[{\"type\":\"b\"}]}"); LinkedHashSetPojo pojo = MAPPER.readValue(json, LinkedHashSetPojo.class); LinkedHashSet<I> restored = pojo.getValue(); Assert.assertEquals(restored.filter(e -> e instanceof B).length(), 1); }
@Test public void testLinkedHashSet() throws Exception { LinkedHashSet<A> src = LinkedHashSet.of(new B("a", "b")); String json = MAPPER.writeValueAsString(new LinkedHashSetPojo().setValue(src)); Assert.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); LinkedHashSetPojo pojo = MAPPER.readValue(json, LinkedHashSetPojo.class); LinkedHashSet<A> restored = pojo.getValue(); Assert.assertEquals(restored.filter(e -> e instanceof B).length(), 1); Assert.assertEquals(restored.head().a, "a"); Assert.assertEquals(((B) restored.head()).b, "b"); }