owlike/genson

Blocking on invalid JSON input - no error (e.g. Exception)

Closed this issue · 2 comments

I'm using the streaming API of Genson (version 1.4). When I parse an invalid JSON string, it blocks on the method objectReader.next(). I do not get any error output (e.g. Exceptions). If the data is valid, it works of course! I am reading to following data:

{
	foo : "bar"
}

with

Genson genson = new Genson();
ObjectReader objectReader = genson.createReader(data);
switch(objectReader.next()) {
    case ARRAY:
        return this.readArray(objectReader);
    case OBJECT:
        return this.readObject(objectReader);
    default:
        throw new DataConversionException("No JSON structure (object or array)!");
}
[...]
private Object readObject(ObjectReader objectReader) {
    objectReader.beginObject();
    while(objectReader.hasNext()) {
        objectReader.next(); // Does not return!
        object.put(objectReader.name(), this.readValue(objectReader));
    }
    objectReader.endObject();
}

btw. Object is not a java.lang.Object. Don't be confused!

Can you post a fully reproducible example?
When trying to reproduce it I get an exception just as expected:
Exception in thread "main" com.owlike.genson.stream.JsonStreamException: Encountred misplaced character 'f' around row 0 and column 1.

Ok, I had some trouble with catching the Exception in a new thread. Thanks for the hint. However, I find it inconvenient to use a RuntimeException. A normal Exception would be better, because this is an error case which should be handled.