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

YassonParser stream and skip methods breaks parser state and DeserializationContext contract #630

Open
api-from-the-ion opened this issue Nov 13, 2023 · 0 comments
Labels
bug Something isn't working right

Comments

@api-from-the-ion
Copy link

Describe the bug
I try to fix the ticket #611 and write the tests, which would test every method of the underlying YassonParser. The issue that I found: if you use getObjectStream() for example, you can't go past the end of the object you are inside. The parser state is then broken. It doesn't matter which kind of stream methods you are using, all consuming like collect() or just findFirst() to get the first one.

To Reproduce
The reason: we return the stream from delegate but assuming, already before, that the whole object was consumed and lowering the current internal level. But especially in case of the getObjectStream() one can't reach the end of the object using the stream methods itself. So one have to use skipObject() to get to the end of the object, lowering the internal level value to zero. Trying to get the next value, one gets an exception from the validate() method.

Analyzing the situation, a discovered more probably issues. First, all of this stream methods simply returns the according streams from the underlying JsonP parser. Now if one uses this stream, one changes the state of this underlying parser, but YassonParser itself state doesn't change. The bug above is one of examples of such desynchronization.

On the other hand, this parser maintains the last event state in the given context by using setLastValueEvent() method. This is clearly not happens in case of the stream using and the skip methods.

Expected behavior
I expect to use stream methods without any side effects

System information:

  • OS: Linux
  • Java Version: 17
  • Yasson Version: 3.0.3

Additional context
I'll create a patch: I already implemented the stream methods in the JsonStructureToParserAdapter #625, where they were missed. The implementation using the hasNext(), next() and getValue() methods of the parser. I'll extract this code into a class which could create such streams for any given parser. And correct the skip methods; and write the test for all of this, so the code coverage of the YassonParser will reach 100%.

@api-from-the-ion api-from-the-ion added the bug Something isn't working right label Nov 13, 2023
api-from-the-ion added a commit to api-from-the-ion/yasson that referenced this issue Nov 13, 2023
…he YassonParser's skipXXX and streamXXX methods

Signed-off-by: Anton Pinsky <anton.pinsky@ionos.com>
api-from-the-ion added a commit to api-from-the-ion/yasson that referenced this issue Nov 13, 2023
Signed-off-by: Anton Pinsky <anton.pinsky@ionos.com>
api-from-the-ion added a commit to api-from-the-ion/yasson that referenced this issue Nov 24, 2023
… etc. implementation; YassonParser & JsonStructureToParserAdapter fulfill more JSONP JsonParser

Signed-off-by: Anton Pinsky <anton.pinsky@ionos.com>
api-from-the-ion added a commit to api-from-the-ion/yasson that referenced this issue Nov 24, 2023
…\_(ツ)_/¯

Signed-off-by: Anton Pinsky <anton.pinsky@ionos.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests

1 participant