You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by sm...@apache.org on 2024/03/04 12:20:50 UTC
(knox) branch master updated: KNOX-2995 - Support json parsing NaN values (#828)
This is an automated email from the ASF dual-hosted git repository.
smolnar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new bd3972d94 KNOX-2995 - Support json parsing NaN values (#828)
bd3972d94 is described below
commit bd3972d94b30a96d55035b93746e975bdd02d599
Author: berylzsh <50...@users.noreply.github.com>
AuthorDate: Mon Mar 4 20:20:44 2024 +0800
KNOX-2995 - Support json parsing NaN values (#828)
---------
Co-authored-by: zhaoshuaihua <zh...@kingsoft.com>
---
.../knox/gateway/filter/rewrite/impl/json/JsonFilterReader.java | 6 ++++++
.../gateway/filter/rewrite/impl/json/JsonFilterReaderTest.java | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReader.java
index 87bbe5150..63e30cda4 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReader.java
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -77,6 +78,11 @@ class JsonFilterReader extends Reader {
bufferingLevel = null;
bufferingConfig = null;
this.config = config;
+ jsonParserConfigInit();
+ }
+
+ private void jsonParserConfigInit() {
+ parser.enable( JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS.mappedFeature() );
}
@Override
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReaderTest.java b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReaderTest.java
index c659da505..eec2bafb0 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReaderTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/knox/gateway/filter/rewrite/impl/json/JsonFilterReaderTest.java
@@ -92,6 +92,15 @@ public class JsonFilterReaderTest {
}
}
+ @Test
+ public void testNaN() throws IOException {
+ String inputJson = "NaN";
+ StringReader inputReader = new StringReader( inputJson );
+ JsonFilterReader filterReader = new TestJsonFilterReader( inputReader, null );
+ String outputJson = new String( IOUtils.toCharArray( filterReader ) );
+ JsonAssert.with(outputJson).assertThat("$", is(inputJson));
+ }
+
@Test
public void testNull() throws IOException {
String inputJson = "null";