Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Suppose you have a java bean say an employee bean such as. Add the tags to tell </p> <pre><code>@XmlRootElement (name = "Employee") public class Employee { String employeeName; @XmlElement public String getEmployeeName() { return employeeName; } public void setEmployeeName(String employeeName) { this.employeeName = employeeName; } } </code></pre> <p>@XmlRootElement tells that this will be the main tag in xml. In this case you can specify a name for the main tag as well.</p> <p>@XmlElement tells that this would be the sub tag inside the root tag</p> <p>Say, the sample xml that will come as a part of body in the post request will look something like</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Employee&gt; &lt;employeeName&gt;Jack&lt;/employeeName&gt; &lt;/Employee&gt; </code></pre> <p>When writing a webservice to acccept such an xml we can write the following method.</p> <pre><code>@POST @Path("/post") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) public Response getEmployee(Employee employee) { employee.setEmployeeName(employee.getEmployeeName() + " Welcome"); return Response.status(Status.OK).entity(employee).build(); } </code></pre> <p>On calling this service, you will get the following xml as part of the response.</p> <pre><code>&lt;Employee&gt; &lt;employeeName&gt; Jack Welcome &lt;/employeeName&gt; &lt;/Employee&gt; </code></pre> <p>using @Xml...annotations, it becomes very easy to unmarshal and marshal the request and response objects.</p> <p>Similar approach can be taken for JSON input as well as JSON output by just using the MediaType.APPLICATION_JSON instead of APPLICATION_XML</p> <p>So for an xml as input, you can get an xml as an output as part of the http response. Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload