views:

41

answers:

1

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;

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

becomes this,

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

So, why are there @ in the name?

+2  A: 

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
Blaise Doughan