JSON answer: Spring with JAXB

Tech Stack: Java 1.6, JAXB, Spring 3, JAX-RS (RESTEasy), XSD

Hello,

I am using Spring with JAX-RS to create a RestFul Webservice.

Everything works fine, except that the generated answers contain settings information, for example.

{ ... "setName": true, "setId": true, "setAddress": true, "setAge": true, } 

I do not know what could be the reason for this? How to disable this?

Adi

UPDATE 1:

The PersonRequest class is generated by JAXB and contains all javax.xml.bind.annotation annotations. *.

 @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "personResponse " }) @XmlRootElement(name = "PersonResponse ") public class PersonResponse { @XmlElement(name = "Name", required = true) protected String name; @XmlElement(name = "Id", required = true) protected String id; // and the setters and getters } 

and the resource is as follows:

 @Component @Path("/person") public class PersonImpl implements Person { @Override @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "application/x-amf" }) @Path("v1") public PersonResponse getPerson() { .... .... } } 

** UPDATE 2 ** This only happens when the Content-Type is json, in the case of a Content Type like "xml", setters are not returned. If it helps.

+1
source share
2 answers

The problem was in the xjb file, see the corresponding question here for details.

0
source

I suspect that some other part of the stack is interwoven into additional fields in your domain model (some ORM libraries do this). To confirm that you can use the java.lang.reflect APIs to find out what fields your class has after it has been loaded using ClassLoader .

0
source

All Articles