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

258 Views Asked by At

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.

1

There are 1 best solutions below

0
Bozho On

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