0

I'm having some trouble with JAXB Marshalling. I'm just going to preface this by saying I'm still learning about marshalling, unmarshalling, and JAXB.

Essentially, I have a REST endpoint that takes in and returns a PriceItem object.

@JsonInclude(JsonInclude.Include.NON_NULL)
@XmlRootElement(name = "priceItem")
@XmlType(propOrder = { "name", "value"})
public class PriceItem implements Comparable<PriceItem> {

    private String name;  
    private Number value;

    @GET
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Path("/name")
    @XmlElement(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @GET
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Path("/value")
    @XmlElement(name = "value")
    public Number getValue() {
       return value;
    }

    public void setValue(Number value) {
        this.value = value;
    }
}

However, when the resulting priceItem is returned as XML, it comes out like

<priceItem>
    <name>Age - All Ages</name>
    <value xsi:type="xs:long" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">29</value>
</priceItem>

The value could be a decimal or an integer, so we use Number. What is the easiest way to ensure I don't get all the extra namespace information on unmarshalling?

EaterOfFromage
  • 351
  • 5
  • 12

0 Answers0