Friday, 18 July 2014

Jersey serializing Integer value by using JacksonJsonProvider



I have a web service in Jersey (2.9.1) and method that has to return a Integer value in XML or JSON depends on Accept header. I am using com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider as a JSON provider. I have moved to this one because of some issues with serialization of single element arrays. But now I have another problem: The returned value should looks like that in XML:



<integer>
<value>1000083</value>
</integer>


and like that in JSON:



{"value":1000083}


but I receive this without single exception



{"fieldHandler": null}


Wrapper code:



@XmlRootElement(name = "integer")
@XmlAccessorType(XmlAccessType.FIELD)
public class IntegerWrapper {

@XmlValue
private Integer value;

@SuppressWarnings("unused")
private IntegerWrapper() {
}

public IntegerWrapper(Integer value) {
this.value = value;
}
}


Any ideas?


No comments:

Post a Comment