Skip to content

Skip malformed JSON object after a parse error#5462

Open
Develop-KIM wants to merge 1 commit into
spring-projects:mainfrom
Develop-KIM:gh-4701-skip-malformed-json-object
Open

Skip malformed JSON object after a parse error#5462
Develop-KIM wants to merge 1 commit into
spring-projects:mainfrom
Develop-KIM:gh-4701-skip-malformed-json-object

Conversation

@Develop-KIM

Copy link
Copy Markdown

JacksonJsonObjectReader.read() rethrows a JacksonException as a ParseException, but it leaves the parser cursor inside the malformed object. The next read() then finds a token other than START_OBJECT and returns null, 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 a ParseException.

With this input the first item reads fine and the second throws ParseException as expected, but the third comes back null instead of CCC:

[
  {"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.

GsonJsonObjectReader reads through a JsonReader and 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. JacksonJsonObjectReaderTests fails on current main (the first two cases) and passes with the fix, and the item.json package suite plus spring-javaformat:validate are green.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Skip Functionality on ParseException in JacksonJsonObjectReader

1 participant