0

How we can add field as an attribute for an element for java REST API

My Java class

@XmlRootElement(name = "rtml_application")
public class ApplicationsEntity extends BaseEntity {
    private static final long serialVersionUID = 3256446889040622647L;
    private Long id;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    private String path;
    public String getPath() {
        return path;
    }
    public void setPath(String path) {
        this.path = path;
    }
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
} 

I want to generate xml response

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rtml_application>
    <created_at type="datetime">2013-06-13T12:33:09.885+05:30</created_at>
    <id type="integer">9</id>
    <name type="string">REST TEST</name>
    <path nil="true"></path>
</rtml_application>

could any please help me out fix this problem using java annotation with jersey.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • Can you be more clearer with your problem. Your title and your description are not making concrete sense . Not able to understand what is your problem. – Juned Ahsan Jun 13 '13 at 08:57
  • Where are the 'type' attributes coming from; why do you need them? Where did the value 'true' for 'nil' magically appear from? – Joeri Hendrickx Jun 13 '13 at 09:04

1 Answers1

0

@XmlAttribute designates a field as an attribute, rather than an element

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140