Unmarshalling Link doesn't seem to work. Try this out:
@XmlRootElement(name="list")
public static class LinksList
{
protected Link other;
protected List<Link> links = new ArrayList<Link>();
@XmlElement(name="link")
@XmlJavaTypeAdapter(value=Link.JaxbAdapter.class, type=Link.class)
public List<Link> getLinks()
{
return links;
}
public void setLinks(List<Link> links)
{
this.links = links;
}
@XmlElement(name="other")
@XmlJavaTypeAdapter(value=Link.JaxbAdapter.class)
public Link getOther()
{
return other;
}
public void setOther(Link other)
{
this.other = other;
}
}
@Test
public void testLinks() throws Exception
{
JAXBContext context = JAXBContext.newInstance(LinksList.class);
LinksList list = new LinksList();
list.getLinks().add(Link.fromUri("/a").rel("self").build());
list.getLinks().add(Link.fromUri("/b").rel("father").build());
list.setOther(Link.fromUri("/c").rel("other").build());
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(list, writer);
String xml = writer.getBuffer().toString();
System.out.println(xml);
System.out.println("----");
list = (LinksList)context.createUnmarshaller().unmarshal(new
ByteArrayInputStream(xml.getBytes()));
context.createMarshaller().marshal(list, System.out);
}
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com