-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Jackson parsing readTree() does not fail for invalid json text #808
Comments
Wrong repo; would belong under But this is intended behavior, not a bug: Jackson only reads as much content as it needs for a valid JSON Value. It does not try to consume everything there might be available, given that the white-space-separated content streams are commonly used. Having said that, there is a way to do what you want by enabling
on This was added in Jackson 2.9, as per: |
Thx for response and suggested solution. I was inicially creating the issue in databind, but then I thought this was a better place. My bad. I wont pretend to understand why this is intended behavior and I understand that sometimes real world is messy and the software needs to go outside the spec to accommodate most people, but json library parsing invalid json ok by default seems like quite a misstep. Well, hopefully your suggestion will work, so that rightfully closes this issue. I'll read through reasoning in your link and report if your solution will not work properly (which im certain it will). |
The suggested fix works. Thx for quick response. However, after reading the linked issue and couple related issues, I remain unconvinced that this is reasonable default for json library. Take that information however you will. |
@ImABird001 I disagree with your "invalid JSON" part. Content that is read is fully valid -- it is just not the whole input. So it is invalid for YOUR use case, fine. Whether this should be the default behavior or not is of course matter of opinion. |
Jackson parses invalid text (numbers separated by space) and produces valid JsonNode. Expectation is to get an exception. I have tried few alternative ways of parsing, but so far jackson pretends the text is valid and returns first number. I discovered this by accident by validating user supplied text as json and getting true.
new JsonMapper().readTree("1 2") // produces IntNode(1)
new ObjectMapper().readTree("1 2") // produces IntNode(1)
The text was updated successfully, but these errors were encountered: