我已经开发了运行良好的 RESTful Web 服务我使用了一个 POJO 和一个服务类,如下所示,但问题是在输出中它显示了额外的 $ 请告知如何更正现在输出为
{
"student":{
"@id":"10",
"age":{
"$":"25"
},
"collegeName":{
"$":"UP College"
},
"name":{
"$":"Ram"
}
}
}
我希望输出应该是
{
"student":{
"@id":"10",
"age":25,
"collegeName":"UP College",
"name":"Ram"
}
}
所以下面是我的 POJO
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "student")
public class Student {
private int id;
private String name;
private String collegeName;
private int age;
@XmlAttribute
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement
public String getCollegeName() {
return collegeName;
}
public void setCollegeName(String collegeName) {
this.collegeName = collegeName;
}
public int getAge() {
return age;
}
@XmlElement
public void setAge(int age) {
this.age = age;
}
}
下面是我的服务类
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jboss.resteasy.annotations.providers.jaxb.json.BadgerFish;
@Path("/restwb")
public class StudentService {
@BadgerFish
@GET
//@Path("/{id}")
@Produces("application/json")
public Student getStudentDetails(){
Student student = new Student();
student.setId(10);
student.setName("Ram");
student.setCollegeName("UP College");
student.setAge(25);
return student;
}
}
这是我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.concretepage</groupId>
<artifactId>RestWB</artifactId>
<version>1</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jettison-provider</artifactId>
<version>3.0.4.Final</version>
</dependency>
</dependencies>
</project>