changeset 584:efbdaf72aafe 3.2.x

JSON is not restricted to ASCII
author Tom Gottfried <tom@intevation.de>
date Thu, 02 Nov 2023 17:41:10 +0100
parents 0135bf3bd92b
children 0960b825516a
files artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/JSON.java artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java
diffstat 2 files changed, 9 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/JSON.java	Thu Nov 02 15:09:22 2023 +0100
+++ b/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/JSON.java	Thu Nov 02 17:41:10 2023 +0100
@@ -78,18 +78,7 @@
                 case '\n': sb.append("\\n"); break;
                 case '\b': sb.append("\\b"); break;
                 case '\f': sb.append("\\f"); break;
-                default:
-                    if (c >= 128) {
-                        sb.append("\\u");
-                        String hex = Integer.toHexString((int)c);
-                        for (int j = 4-hex.length(); j > 0; --j) {
-                            sb.append('0');
-                        }
-                        sb.append(hex);
-                    }
-                    else {
-                        sb.append(c);
-                    }
+                default: sb.append(c);
             }
         }
 
--- a/artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java	Thu Nov 02 15:09:22 2023 +0100
+++ b/artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java	Thu Nov 02 17:41:10 2023 +0100
@@ -26,4 +26,12 @@
             + "}",
             JSON.toJSONString(json));
     }
+
+    @Test
+    public void toNonASCIIJSONString() {
+        final Map<String, Object> json = new HashMap<>();
+        json.put("täst", "täst");
+
+        assertEquals("{\"täst\":\"täst\"}", JSON.toJSONString(json));
+    }
 }

http://dive4elements.wald.intevation.org