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

Restore strict mode text parsing #921

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

stleary
Copy link
Owner

@stleary stleary commented Dec 15, 2024

What problem does this code solve?

The default JSON-Java library is quite permissive in allowing invalid JSON docs to be parsed successfully. The "strict mode" feature is for users who need the library to enforce valid JSON text.

A few months ago, strict mode was added but it was not fully completed. As a result, the code was backed out temporarily and is now restored, with some updates to complete the implementation.

Strict mode is only available when parsing JSON from a text document.
To enable strict mode, use code like the following:

        JSONParserConfiguration jsonParserConfiguration = 
                new JSONParserConfiguration()
                .withStrictMode(true);
        JSONObject jsonObject = new JSONObject(myString, jsonParserConfiguration));

To test for regressions, update the JSONParserConfiguration class to have strict mode enabled by default. Then build the project and run the unit tests, which should all complete successfully.

Does the code still compile with Java6?
Yes

Risks
Low

Changes to the API?
The original strict mode API has been restored.

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No. Some tests that used invalid JSON text have been fixed. A few tests that specifically use invalid text are skipped when strict mode is defaulted. (see regression testing discussion above). New unit tests were added.

Was any code refactored in this commit?
The internal implementation of strict mode has been updated.

Review status

@stleary stleary changed the title Restore jsonparserconfiguration Restore strict mode text parsing Dec 15, 2024
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.

1 participant