FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
316 stars 136 forks source link

Infinite sequence of `END_OBJECT` tokens returned at end of streaming read #135

Closed wanglingsong closed 6 years ago

wanglingsong commented 6 years ago

Jackson version: 2.9.4 I'm trying to use streaming JsonParser to parse protobuf binary data according to your example, however the nextToken method keep returning "END_OBJECT" token in the end of parsing. You can reproduce this issue by following code:

        ObjectMapper mapper = new ProtobufMapper();
        String protobuf_str = "message Employee {\n"
                + " required string name = 1;\n"
                + " required int32 age = 2;\n"
                + " repeated string emails = 3;\n"
                + " optional Employee boss = 4;\n"
                + "}\n";
        final ProtobufSchema schema = ProtobufSchemaLoader.std.parse(protobuf_str);

        Employee empl = new Employee();
        empl.age = 30;
        empl.emails = new String[]{"foo@gmail.com"};
        empl.name = "foo";

        byte[] protobufData = mapper.writer(schema)
                .writeValueAsBytes(empl);

        JsonParser jsonParser = new ProtobufFactory().createParser(new ByteArrayInputStream(protobufData));
        jsonParser.setSchema(schema);
        JsonToken token;
        while ((token = jsonParser.nextToken()) != null) {
            System.out.println(token.id());
        }

output:

1
5
6
5
7
5
3
6
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...endless
cowtowncoder commented 6 years ago

Thank you for reporting this. It does sound like a bug.

One minor request: if it is easy enough, could you verify it still fails with 2.9.5? I assume it does as I do not recall fix to specific problem. But there have been recent fixes to protobuf module.

wanglingsong commented 6 years ago

Checked. Still fails with 2.9.5

cowtowncoder commented 6 years ago

Ok, I can reproduce the issue. Seems to require non-empty array, for what that is worth, probably as the last value.

cowtowncoder commented 6 years ago

Fixed for 2.9.6.