Jersey/JAXB/XML/JSON: Adding elements to documents created from POJOs -


I'm new to Jersey, JACAB, and JSON, and quite a lot with XML. I am playing with a simple web service (attempt to become RESTful)

Looking at the following POJO:.

  @XmlRootElement public square POJO {. . @ XmlElement public string getProp1 {return prop1; } @ XmlElement public string getProp2 {return prop2; }}   

and the following resource class:

  @ path ("/ resources) public class resources {@Path (" / pojo ") @GET @ Produces ({"application / xml", "application / json"}) public POJO getPojo () {POJO POJO = new POJO (); pojo.setProp1 ("foo"); pojo.setProp2 ("bar"); return POJO ;}}   

Request for the proper URI XML and JSON I expect the return:

    

Next, I use the following output products I want to update service for:

  & lt ;? xml version = "1.0" encoding = "UTF-8"? & Gt; & lt; POJO & gt; & lt; Prop1 & gt; foo & lt; / prop1 & gt; & lt; prop2 & gt; Bar & lt; / prop2 & gt; & lt; link & gt; http: // coolURI & lt; / link & gt; Lt; / POJO & gt; {"prop1": "foo", "prop2": "bar", "link": "http: // coolURI"}   

where "coolURI ", There is a hyperMedia indicator for the next resource and obviously there is no property of class P. Ojo, so its value XML will be martial in a different way. Please point me to the mechanism to work and I should thank you for your help.

You have to return anything other than a POJO with your derivative () method. Either an extended POJO that includes a link, or links to any response object in some way.

Comments