-
-
Notifications
You must be signed in to change notification settings - Fork 76
fix Issue 177 (support incomplet json messages) #254
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
Conversation
- Introduced ACCEPT_INCOMPLETE mode in JSONParser to allow parsing of incomplete JSON data. - Updated JSONParserBase and related classes to handle incomplete data scenarios. - Added unit tests for various incomplete JSON cases in JSONIncompletModeTest.
@@ -89,6 +89,7 @@ abstract class JSONParserBase { | |||
protected final boolean reject127; | |||
protected final boolean unrestictBigDigit; | |||
protected final boolean limitJsonDepth; | |||
protected final boolean acceptIncomplet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected final boolean acceptIncomplet; | |
protected final boolean acceptIncomplete; |
I removed ACCEPT_INCOMPLETE from MODE_PERMISSIVE. and add a new MODE_PERMISSIVE_NEW that enabling all the flag. and I think that this change need some extra doc. /**
* smart mode, fastest parsing mode. accept lots of non standard json syntax ACCEPT_INCOMPLETE
* feature is not enabled. in this mode, for backward compatibility
*
* @since 1.0.6
*/
public static final int MODE_PERMISSIVE = -1 & ~ACCEPT_INCOMPLETE;
/*
* smart mode, fastest parsing mode. accept lots of non standard json syntax
* ACCEPT_INCOMPLETE feature is enabled.
* @since 2.6
*/
public static final int MODE_PERMISSIVE_NEW = -1; |
It took me some figuring out how to set this to revert to the previous behaviour. Our framework needs to not accept invalid (incomplete) JSON, so we rely on an exception to be thrown. This PR changes that, but we managed to fix this in our code by providing a custom
to this:
(Where 'jsonPath' is an instance of |
This pull request introduces several changes to the
json-smart
library, focusing on enhancing JSON parsing capabilities, particularly handling incomplete JSON data, and improving theJSONArray
class. Additionally, new tests have been added to ensure the robustness of these changes.Enhancements to JSON Parsing:
ACCEPT_INCOMPLETE
mode inJSONParser
to handle incomplete JSON data without throwing exceptions. (json-smart/src/main/java/net/minidev/json/parser/JSONParser.java
,[[1]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-830157417c74f070871740621ea069ffe04604e403d3343307107f171f74ecafR110)
,[[2]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-830157417c74f070871740621ea069ffe04604e403d3343307107f171f74ecafR318-R321)
,[[3]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-830157417c74f070871740621ea069ffe04604e403d3343307107f171f74ecafR500-R504)
,[[4]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-830157417c74f070871740621ea069ffe04604e403d3343307107f171f74ecafL575-R594)
,[[5]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-830157417c74f070871740621ea069ffe04604e403d3343307107f171f74ecafL596-R621)
,[[6]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-830157417c74f070871740621ea069ffe04604e403d3343307107f171f74ecafR642-R645)
,[[7]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-438d4942deb16b9e1899fa483659aab17216efe1cb9bc9eba58e8f67a3767270R99)
,[[8]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-3dbcfe7eee09bbe7086d6121c5cf5eb1bc2e9887063c3e2a212990f8794014f0L116-R122)
,[[9]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-134bd6fa957e8f06677273d1ae9e218395081504bfe0aa3f9c3221abf312232cL85-L87)
,[[10]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-45f79fc2d5acbf469cfa58a78ef9f5e5f226dc005cd2383f29707956acfa79f4R96)
)Improvements to
JSONArray
:JSONArray
class by removing the redundantList<Object>
interface implementation. (json-smart/src/main/java/net/minidev/json/JSONArray.java
,[json-smart/src/main/java/net/minidev/json/JSONArray.javaL29-R29](https://github.com/netplex/json-smart-v2/pull/254/files#diff-2cf87304548f5847ac3522c793260781657696d6af643164d1cf4176a9316769L29-R29)
)JSONArray
. (json-smart/src/main/java/net/minidev/json/JSONArray.java
,[[1]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-2cf87304548f5847ac3522c793260781657696d6af643164d1cf4176a9316769R78-R92)
,[[2]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-2cf87304548f5847ac3522c793260781657696d6af643164d1cf4176a9316769R102-R106)
,[[3]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-2cf87304548f5847ac3522c793260781657696d6af643164d1cf4176a9316769R134-R148)
)Bug Fixes:
JSONUtil
to ensure proper conversion of objects to primitive types. (json-smart/src/main/java/net/minidev/json/JSONUtil.java
,[[1]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-93020ec571518cb282b95f14803076c4f163abdeb8670038221519ef7b9af110L48-R52)
,[[2]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-93020ec571518cb282b95f14803076c4f163abdeb8670038221519ef7b9af110L76-R83)
,[[3]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-93020ec571518cb282b95f14803076c4f163abdeb8670038221519ef7b9af110L97-R106)
,[[4]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-93020ec571518cb282b95f14803076c4f163abdeb8670038221519ef7b9af110L125-R137)
)Documentation:
README.md
to include a new section for version 2.5.2 and its changes. (README.md
,[README.mdR26](https://github.com/netplex/json-smart-v2/pull/254/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R26)
)Testing:
ACCEPT_INCOMPLETE
mode and ensure the correct functionality ofJSONArray
methods. (json-smart/src/test/java/net/minidev/json/test/JSONIncompletModeTest.java
,[[1]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-b6c30ff715327fcca062c314b765a2bf45ce79492a3c58a1b6b204f59d9a9832R1-R80)
,json-smart/src/test/java/net/minidev/json/test/unit/TestJSONArrayTest.java
,[[2]](https://github.com/netplex/json-smart-v2/pull/254/files#diff-4c16fa82921ee370379f1877e65820be0c122b03774ee9cdf2794c013710b154R1-R88)
)