Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wanglingsong opened this issue May 16, 2018 · 4 comments
Closed
Labels
Milestone

Comments

@wanglingsong
Copy link

wanglingsong commented May 16, 2018

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
Copy link
Member

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
Copy link
Author

Checked. Still fails with 2.9.5

@cowtowncoder cowtowncoder changed the title [protobuf] Return endless END_OBJECT token in streaming JsonParser Infinite sequence of END_OBJECT tokens returned at end of streaming read May 17, 2018
@cowtowncoder
Copy link
Member

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

cowtowncoder added a commit that referenced this issue May 17, 2018
@cowtowncoder cowtowncoder added this to the 2.9.6 milestone May 17, 2018
@cowtowncoder
Copy link
Member

Fixed for 2.9.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants