tags:

views:

89

answers:

2

I have a response from a REST web service that looks like this:-

{"number":447919191231,"messages":"","receipt":{"uid":"5d1bddf5-1b98-4a32-8ebf-f71c3973e7a8","messages":"","status":"SUCCESS","code":"09641","ttl":120,"url":"http:\/\/server:8080\/x\/d6985"}}

and I am attempting to use the method outlined here in the full data binding example

http://wiki.fasterxml.com/JacksonInFiveMinutes#Full_Data_Binding_.28POJO.29_Example

I have created a class which looks like this:-

public class ReceiptResponse {

    private int _number;
    private String _messages;
    private Receipt _receipt;

    public int getNumber() { return _number; }
    public void setNumber(int number) { this._number = number; }
    public String getMessages() { return _messages; }
    public void setMessages(String messages) { this._messages = messages; }
    public Receipt getReceipt() { return _receipt; }
    public void setReceipt(Receipt receipt) { this._receipt = receipt; }

public static class Receipt {
        private String _uid;
        private String _messages;
        private String _status;
        private int _code;
        private int _ttl;
        private String _url;

        public String getUid() { return _uid; }
        public void setUid(String uid) { this._uid = uid; }
        public String getMessages() { return _messages; }
        public void setMessages(String messages) { this._messages = messages; }
        public String getStatus() { return _status; }
        public void setStatus(String status) { this._status = status;}
        public int getCode() { return _code; }
        public void setCode(int code) { this._code = code; }
        public int getTtl() { return _ttl; }
        public void setTtl(int ttl) { this._ttl = ttl; }
        public String getUrl() { return _url; }
        public void setUrl(String url) { this._url = url; }
    }
}

My code to parse this response looks like this:-

ObjectMapper mapper = new ObjectMapper(); 
ReceiptResponse response = mapper.readValue(method.getResponseBodyAsStream(), ReceiptResponse.class);

But it throws the following error:-

12:03:44,195 ERROR [STDERR] Fatal transport error: No content to map to Object due to end of input
12:03:44,195 ERROR [STDERR] java.io.EOFException: No content to map to Object due to end of input
12:03:44,196 ERROR [STDERR]     at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:1630)
12:03:44,196 ERROR [STDERR]     at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:1580)
12:03:44,196 ERROR [STDERR]     at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1158)

Can anyone help me by explaining why this is happening? I thought perhaps it was because the messages are empty, but I tried putting dummy data in there and it still failed. I've looked for the ObjectMapper code and it seems to think it can't find the first token (am i correct?) but I can't see why it won't be able to find it?

any help would be appreciated!

A: 

How did you do that mate?? Could you please post the solution...

-- Anish Sneh

Anish Sneh
A: 

I just ran into the same issue. I had an inordinately long stream from the response. Converting it to a String helped get past the initial exception. That didn't solve everything, though, so I ended up adding 0-arg constructors to all of the pojos involved in the mapping. The mapper worked perfectly after that.

jrb