users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: unmarshalling Link

From: Bill Burke <bburke_at_redhat.com>
Date: Wed, 28 Aug 2013 20:11:24 -0400

The problem stems from a missing setter method in Link.JaxbLink

         public void setUri(URI uri) {
             this.uri = uri;
         }

If you add that then unmarshalling works. If you don't add this then
the URI property will always be NULL.

The concern I have is, if I fix this I will fail the signature tests of
the TCK. Is this something that can be challenged?

https://java.net/jira/browse/JAX_RS_SPEC-422

On 8/28/2013 11:27 AM, Bill Burke wrote:
> 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