为什么使用Jersey在JSON中使用@返回名称 [英] Why are names returned with @ in JSON using Jersey

查看:75
本文介绍了为什么使用Jersey在JSON中使用@返回名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用作为Jersey JAX-RS一部分的JAXB。当我为输出类型请求JSON时,我的所有属性名称都以这样的星号开头,

I am using the JAXB that is part of the Jersey JAX-RS. When I request JSON for my output type, all my attribute names start with an asterisk like this,

此对象;

package com.ups.crd.data.objects;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@XmlType
public class ResponseDetails {
    @XmlAttribute public String ReturnCode = "";
    @XmlAttribute public String StatusMessage = "";
    @XmlAttribute public String TransactionDate ="";
}

变为此,

   {"ResponseDetails":{"@transactionDate":"07-12-2010",  
             "@statusMessage":"Successful","@returnCode":"0"}

那么,为什么名字中有@?

So, why are there @ in the name?

推荐答案

使用@XmlAttribute映射的任何属性都将在JSON中以@为前缀。如果要删除它,只需使用@XmlElement注释您的属性。

Any properties mapped with @XmlAttribute will be prefixed with '@' in JSON. If you want to remove it simply annotated your property with @XmlElement.

大概这是为了避免潜在的名称冲突:

Presumably this is to avoid potential name conflicts:

@XmlAttribute(name="foo") public String prop1;  // maps to @foo in JSON
@XmlElement(name="foo") public String prop2;  // maps to foo in JSON

这篇关于为什么使用Jersey在JSON中使用@返回名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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