michel-kraemer/bson4jackson — Issue #10: BsonParser.nextToken() throws JsonParseException instead of returning null
Author: hertzsprung
Created: 2011-11-30 17:22:04+00:00
State: open

The javadoc for JsonParser states that the parser should return null when there are no more tokens available, but this isn't what happens:

```java
public class BsonTest {
public static void main(String[] args) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
BsonFactory bsonFactory = new BsonFactory();
BsonGenerator generator = bsonFactory.createJsonGenerator(out);
generator.writeStartObject();
generator.writeStringField("myField", "myValue");
generator.writeEndObject();
generator.close();

JsonParser parser = bsonFactory.createJsonParser(out.toByteArray());
while (parser.nextToken() != null) {
System.out.println(parser.getCurrentToken());
}
}
}
```
Gives:

```
START_OBJECT
FIELD_NAME
VALUE_STRING
END_OBJECT
Exception in thread "main" org.codehaus.jackson.JsonParseException: Found element outside the document
at [Source: de.undercouch.bson4jackson.io.LittleEndianInputStream@ce102dc; pos: 23]
at de.undercouch.bson4jackson.BsonParser.nextToken(BsonParser.java:125)
at BsonTest.main(BsonTest.java:20)
```

Tested with baaec01036