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

KNOX-2995 - Support json parsing NaN values #828

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

upczsh
Copy link
Contributor

@upczsh upczsh commented Dec 19, 2023

What changes were proposed in this pull request?

Implemented the changes I listed in KNOX-2995:

  • Solve the problem of page parsing failure when Json returns NaN value.

Added JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS.mappedFeature() to support this feature

I click on the page with return json and the content of Resopnse is empty. like this :

image

Checking the gateway.log log shows the following error message.
image

The display results after my repair are as follows:
image

How was this patch tested?

I have added test cases. You can run the test cases to see if they are successful.
Run JsonFilterReaderTest.testNaN() function.
Or look at the actual problems I encountered above to test.

@upczsh upczsh changed the title KNOX-2995 - Support json parsing NaN values Support json parsing NaN values Dec 19, 2023
@upczsh upczsh changed the title Support json parsing NaN values KNOX-2995:Support json parsing NaN values Dec 28, 2023
@upczsh upczsh changed the title KNOX-2995:Support json parsing NaN values KNOX-2995 - Support json parsing NaN values Dec 28, 2023
@upczsh
Copy link
Contributor Author

upczsh commented Dec 29, 2023

you can see this issuse: KNOX-2995

@smolnar82
Copy link
Contributor

@upczsh - could you please be more verbose on the PR description above?
We do provide a template OOTB, which we require to be filled in when someone opens a PR.
See this one as a recent sample: #826

}

private void jsonParserConfigInit() {
parser.enable(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you add this feature when creating the factory in line 69?
Moreover, the referenced feature has been deprecated since 2.10 according to Jackson docs (we use 2.11.4 in Knox already):

        /**
         * Feature that allows parser to recognize set of
         * "Not-a-Number" (NaN) tokens as legal floating number
         * values (similar to how many other data formats and
         * programming language source code allows it).
         * Specific subset contains values that
         * <a href="http://www.w3.org/TR/xmlschema-2/">XML Schema</a>
         * (see section 3.2.4.1, Lexical Representation)
         * allows (tokens are quoted contents, not including quotes):
         *<ul>
         *  <li>"INF" (for positive infinity), as well as alias of "Infinity"
         *  <li>"-INF" (for negative infinity), alias "-Infinity"
         *  <li>"NaN" (for other not-a-numbers, like result of division by zero)
         *</ul>
         *<p>
         * Since JSON specification does not allow use of such values,
         * this is a non-standard feature, and as such disabled by default.
          *
          * @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_NON_NUMERIC_NUMBERS} instead
          */
         @Deprecated
         ALLOW_NON_NUMERIC_NUMBERS(false),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smolnar82 Thanks for your guidance, I have used JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS instead of the deprecated JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS.
On the other hand, the reason for not adding it on line 69 is that this setting is the content of parse, and other json parse configurations may be enabled in the future, so I wrote a separate method.

…the deprecated JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS
Copy link
Contributor

@smolnar82 smolnar82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smolnar82
Copy link
Contributor

@upczsh - could you please be more verbose on the PR description above?
We do provide a template OOTB, which we require to be filled in when someone opens a PR.
See this one as a recent sample: #826

@smolnar82
Copy link
Contributor

@upczsh - We are about to release Knox v2.1.0 and I'd like to include your change.
However, I cannot merge it until you update the PR description as requested above.
Thanks!

@upczsh
Copy link
Contributor Author

upczsh commented Mar 4, 2024

@upczsh - We are about to release Knox v2.1.0 and I'd like to include your change. However, I cannot merge it until you update the PR description as requested above. Thanks!

terribly sorry!!! I have updated the PR description.It's my honor to contribute!

@smolnar82 smolnar82 merged commit bd3972d into apache:master Mar 4, 2024
2 checks passed
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.

2 participants