1

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

Hello,

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

Everything is working fine except that the generated responses contain the setters info e.g.

  {
    ...

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

I don't know what might be causing this? How can I turn this off?

Adi

UPDATE 1:

The PersonRequest class is generated by the JAXB and contains all the 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 looks like this:

@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 happens only when Content-Type is json, in case of Content Type as 'xml', the setters are not returned. If that helps.

adi
  • 1,711
  • 3
  • 29
  • 50
  • Shouldn't that `propOrder` be `{ "name", "id" }` rather than `{ "personResponse " }`? – Ian Roberts Sep 27 '12 at 12:47
  • yes, maybe. These beans are autogenerated and created this sample only for advice. I didnt posted the original code as it was too big – adi Sep 27 '12 at 15:08

2 Answers2

0

I suspect some other part of the stack is weaving in extra fields to your domain model (I.e some ORM libraries do this). To confirm you could use the java.lang.reflect APIs to see what fields your class has after it had been loaded by the ClassLoader.

bdoughan
  • 147,609
  • 23
  • 300
  • 400
0

Problem was in the xjb file, for details look in the related question here.

Community
  • 1
  • 1
adi
  • 1,711
  • 3
  • 29
  • 50