users@jersey.java.net

Error with java.lang.Integer body reader

From: Steve Mactaggart <steve.mactaggart_at_gmail.com>
Date: Wed, 16 Sep 2009 13:46:28 +1000

Hi all,

I have an application that consumes a Jersey endpoint, that has been
working for weeks, but all of a sudden has stopped working. I have
made what I believe to be un-related changes to the codebase but I
guess I have changed something. The changes were in relation to some
jersey "server" endpoints this app provides, but my issue seems to be
with the Jersey client.

It looks like the default mapping for java.lang.Integer seems to have
been lost..

If I request the url in a browser:
http://127.0.0.1:8080/data-14-SNAPSHOT/pricescale

I get valid XML..
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><priceScaleList><elements><name>Retail</name><order>1</order><priceScaleID>1</priceScaleID></elements><elements><name>Wholesale</name><order>2</order><priceScaleID>2</priceScaleID></elements><elements><name>Trade</name><order>3</order><priceScaleID>3</priceScaleID></elements></priceScaleList>

If I use the Jersey Client to retrieve this it fails with the below
error message.

16 Sep 09 13:34:32:btpool0-1:GenericResource :ERROR : A message
body reader for Java type, class java.lang.Integer, and MIME media
type, application/xml, was not found
com.sun.jersey.api.client.ClientHandlerException: A message body
reader for Java type, class java.lang.Integer, and MIME media type,
application/xml, was not found
        at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:526)
        at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:491)
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:561)
        at com.sun.jersey.api.client.WebResource.get(WebResource.java:179)
        at au.com.us.util.rest.BaseJerseyClient.get(BaseJerseyClient.java:159)
        at au.com.us.util.rest.GenericJerseyClient.findAll(GenericJerseyClient.java:92)
        at au.com.us.business.webapi.GenericResource.listElementsGET(GenericResource.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)

The Java Class' are the same one used in the client as well as the server..
The endpoint returns a PriceScaleList, which is a wrapper for a list
of PriceScale objects.

@XmlRootElement
public class PriceScaleList implements GenericList<PriceScale> {

        private List<PriceScale> elements;

        public PriceScaleList() {
        }
        
        public PriceScaleList(List<PriceScale> elements) {
                this.elements = elements;
        }

        public void setElements(List<PriceScale> elements) {
                this.elements = elements;
        }

        public List<PriceScale> getElements() {
                return elements;
        }

        @Override
        public List<PriceScale> getActualElements() {
                return getElements();
        }
}

@XmlRootElement
public class PriceScale implements Entity {

        private Integer priceScaleID;
        private String name;
        private Integer order;

        public PriceScale() {
        }

        public PriceScale(Integer id) {
                this.priceScaleID = id;
        }

<snipped 3x getter/setter>
}

Any ideas what this issue is? Googling the mailing list and the wider
internet didn't turn up much.

Cheers,
Steve