question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parser don't throw exception when specific JSON is not valid

See original GitHub issue

Describe the bug When trying to parse invalid JSON, the parser doesn’t throw ParseException but parse the JSON. JSON:

{}something

Simple test:

public class JsonParseTest {

    @Test
    void testParsingJson()  {
        ObjectMapper objectMapper = new ObjectMapper();

        assertThrows(JsonParseException.class, () -> objectMapper.readTree("{}something"));
    }
}

Version information 2.13.1

To Reproduce Just run the parsing (readTree or readValue) with incorrect JSON input as shown.

Expected behavior Parser throws JsonParseException

Additional context

Attached simple test project: jackson-parse-error.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Feb 28, 2022

@yawkat Fair enough. Originally I had aversion to unnecessary traversal beyond needed tokens. But that’s probably not much of an argument. Could you please file a separate feature request (issue) for changing FAIL_ON_TRAILING_TOKENS default value for Jackson 3.0? That way I can close this issue.

0reactions
cowtowncodercommented, Mar 29, 2022

Closing as I do not consider it a bug & there is the follow-up issue of possibly changing the default behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Proper way to catch exception from JSON.parse - Stack Overflow
i post something into an iframe then read back the contents of the iframe with json parse...so sometimes it's not a json string....
Read more >
What Is JSON and How to Handle an “Unexpected Token” Error
The first thing to do in this situation is to confirm where the error is happening exactly. To ensure the error happens on...
Read more >
SyntaxError: JSON.parse unexpected character in JavaScript
The "SyntaxError: JSON.parse: unexpected character" error occurs when passing a value that is not a valid JSON string to the JSON.parse method, ...
Read more >
SyntaxError: JSON.parse: bad parsing Breaking Your Code ...
Traveling deftly through to the next item in our JavaScript Error Handling series, today we're taking a hard look at the JSON Parse...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found