Skip malformed JSON object after a parse error#5462
Open
Develop-KIM wants to merge 1 commit into
Open
Conversation
JacksonJsonObjectReader rethrows a JacksonException as a ParseException but leaves the parser cursor inside the malformed object. The next call to read() then finds a token other than START_OBJECT and returns null, which callers treat as the end of the input. The step therefore stops early even though valid items remain, which defeats skipping a ParseException. Skip to the end of the malformed object before rethrowing so that the remaining items stay readable. Resolves spring-projects#4701 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Donghwan Kim <kimdonghwan913@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JacksonJsonObjectReader.read()rethrows aJacksonExceptionas aParseException, but it leaves the parser cursor inside the malformed object. The nextread()then finds a token other thanSTART_OBJECTand returnsnull, which the caller takes as the end of the input, so the step stops early while valid items are still there. That makes it impossible to skip aParseException.With this input the first item reads fine and the second throws
ParseExceptionas expected, but the third comes backnullinstead ofCCC:[ {"isin":"AAA","quantity":1,"price":1.0,"customer":"foo"}, {"isin":"BBB","quantity":"not a number","price":2.0,"customer":"bar"}, {"isin":"CCC","quantity":3,"price":3.0,"customer":"baz"} ]This skips to the end of the malformed object before rethrowing, so the remaining items stay readable. It tracks the nesting depth rather than looking for the next
END_OBJECT, so an item containing nested objects is drained correctly too.GsonJsonObjectReaderreads through aJsonReaderand I didn't touch it here — happy to look at it separately if it has the same gap.Resolves #4701
Written with AI assistance (Claude); I reviewed the change and verified it myself.
JacksonJsonObjectReaderTestsfails on currentmain(the first two cases) and passes with the fix, and theitem.jsonpackage suite plusspring-javaformat:validateare green.