JSON响应:使用JAXB的Spring [英] JSON response: Spring with JAXB

查看:70
本文介绍了JSON响应:使用JAXB的Spring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

技术堆栈:Java 1.6,JAXB,Spring 3,JAX-RS(RESTEasy),XSD

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

您好,

我使用Spring和JAX-RS创建RestFul Web服务。

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

一切正常,但生成的响应包含setter信息,例如

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

更新1:

PersonRequest类由JAXB生成,包含所有javax.xml.bind.annotation。* annotations。

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



}

,资源如下所示:

@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() {

       ....
       ....
    }


}

**更新2 * *
仅当Content-Type为json时才会发生这种情况,如果Content Type为'xml',则不会返回setter。如果这有帮助。

** 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.

推荐答案

问题出现在xjb文件中,有关详细信息请查看相关问题在哪里

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

这篇关于JSON响应:使用JAXB的Spring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆