zaubersoftware/gnip4j — Issue #10: JacksonJsonMapper will throw EOFException if gnip sends \r for every 30 seconds
Author: simonwg
Created: 2012-01-20 10:02:55+00:00
State: open

The case is gnip will send a carriage return for every 30 seconds to make sure that the stream connection is not closed. The problem is JacksonJsonMapper will throw EOFException when receiving this carriage return (refer to _initForReading() of Jackson ObjectMapper.java).

The EOFException will cause the gnip connection be disconnected (although gnip4j will reconnect automatically).

The DefaultGnipStream.java make use of the extended ObjectMapper and override the _initForReading(), which ignore the EOFException for stream class
e.g.

private static class GnipStreamJsonObjectMapper extends ObjectMapper {
@Override
protected JsonToken _initForReading(JsonParser jp)
throws IOException, JsonParseException, JsonMappingException {
/*
* First: must point to a token; if not pointing to one, advance. This
* occurs before first read from JsonParser, as well as after clearing
* of current token.
*/
JsonToken t = jp.getCurrentToken();
if (t == null) {
// and then we must get something...
t = jp.nextToken();
if (t == null) {
/*
* [JACKSON-99] Should throw EOFException, closed thing
* semantically
*/
// throw new EOFException("No content to map to Object due to end of input");
return t;
}
}
return t;
}
}