HalSerializer implements JsonSerializer<HalResource> { protected void dispatchLink(Object value, HalReferenceMetaData metaData, Map<String, List<HalReference>> links) { if (value == null) { return; } if (value instanceof HalReference) { readLink((HalReference) value, metaData, links); } else if (value instanceof Collection) { readLinkCollection((Collection<?>) value, metaData, links); } else { readLinkObject(value, metaData, links); } }  @Override JsonElement serialize(HalResource t, Type type, JsonSerializationContext jsc);  }
@Test public void testDispatchLinkHalReferenceAnn() { HalReference ref = new HalReference(); ref.setHref("/rest"); ref.setTitle("Test"); Map<String, List<HalReference>> links = new HashMap<>(); HalReferenceMetaData metaData = new HalReferenceMetaData(); metaData.setName("self"); adapter.dispatchLink(ref, metaData, links); Assert.assertEquals(1, links.size()); List<HalReference> link = links.get("self"); Assert.assertNotNull(link); Assert.assertEquals(1, link.size()); Assert.assertEquals(ref.getTitle(), link.get(0).getTitle()); }
@Test public void testDispatchLinkCollection() { List<String> refs = new ArrayList<>(); refs.add("test"); refs.add("gugus"); Map<String, List<HalReference>> links = new HashMap<>(); HalReferenceMetaData metaData = new HalReferenceMetaData(); metaData.setName("self"); adapter.dispatchLink(refs, metaData, links); Assert.assertEquals(1, links.size()); List<HalReference> link = links.get("self"); Assert.assertNotNull(link); Assert.assertEquals(2, link.size()); Assert.assertEquals("test", link.get(0).getHref()); Assert.assertEquals("gugus", link.get(1).getHref()); }