From: Danilo C. M. <dco...@gm...> - 2014-09-20 17:22:33
|
Hello there, I am sorry if this message is a duplicate, but I think there was an issue with the delivery of the first one. I am trying to follow an example from RESTEasy's documentation (Chapter 8. Linking resources) in order to have Atom links injected directly into my entity objects, but I simply can't get it to work when I try to return JSON instead of XML. (I believe that I have correctly forced the use of Jettison as per RESTEasy's documentation.) Below are the pertinent code snippets: ArticleResource.java @Path("/article") > public class ArticleResource { > > @Inject > ArticleService articleService; // it just returns fake entities > > @AddLinks > @LinkResource(value = Article.class) > @GET > @Path("{id}") > @Produces("application/json") > public Response getArticle(@PathParam("id") String id) throws Exception > { > Article article = articleService.getArticle(id); > return Response.status(200).entity(article).build(); > } > @LinkResource(value = Article.class) > @POST > @Produces("application/json") > public Response postArticle() throws Exception { > Article article = articleService.createArticle(new Article()); > return Response.status(201).entity(article).build(); > } > } Article.java @Mapped(namespaceMap = @XmlNsMap(jsonName = "atom", namespace = " > http://www.w3.org/2005/Atom > ")) > @XmlRootElement(name = "article") > @XmlAccessorType(XmlAccessType.NONE) > public class Article { > > @XmlID > @XmlAttribute > private String id; > @XmlElementRef > private RESTServiceDiscovery rest; > } And here are the responses I get when I set all the @Produces in ArticleResource.java to "application/xml" <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> > <article id="138"> > <atom:link rel="self" href=" > http://localhost:8080/cad-jax-rs/rest/article/138" /> > <atom:link rel="add" href="http://localhost:8080/cad-jax-rs/rest/article" > /> > </article> and "application/json" { > "id":"138", > "RESTServiceDiscovery":null > } Regarding my Maven pom.xml file, I believe that the important bits are the following: <dependency> > <groupId>org.jboss.resteasy</groupId> > <artifactId>resteasy-jaxrs</artifactId> > <scope>provided</scope> > </dependency> > <dependency> > <groupId>org.jboss.resteasy</groupId> > <artifactId>resteasy-links</artifactId> > </dependency> > <dependency> > <groupId>org.jboss.resteasy</groupId> > <artifactId>resteasy-jaxb-provider</artifactId> > <scope>provided</scope> > </dependency> > <dependency> > <groupId>org.jboss.resteasy</groupId> > <artifactId>resteasy-jettison-provider</artifactId> > <scope>provided</scope> > </dependency> The version numbers are being imported from the resteasy-bom artifact (3.0.8.Final) that is not listed above. Could anyone please try to spot any obvious errors or provide any guidance at all? I would greatly appreciate any help on this matter. In case further information is required, I will gladly provide it. Thank you all in advance. Respectfully yours, Danilo Cominotti Marques P.S.: In case I wanted to use Jackson 2 instead of Jettison, would it be completely impossible to get automatic Atom links injection to work? |