Why are names returned with @ in JSON using Jersey

By : John
Source: Stackoverflow.com

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,

This object;

package com.ups.crd.data.objects;

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

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

becomes this,


So, why are there @ in the name?

By : John


If you are marshalling to both XML and JSON, and you don't need it as an attribute in the XML version then suggestion to use @XmlElement is the best way to go.

However, if it needs to be an attribute (rather than an element) in the XML version, you do have a fairly easy alternative.

You can easily setup a JSONConfiguration that turns off the insertion of the "@".

It would look something like this:

public class JAXBContextResolver implements ContextResolver
By : DaBlick

This video can help you solving your question :)
By: admin