Skip to content

Commit 0ac395c

Browse files
committed
fix(json): retain single trailing comma support
1 parent 48d1381 commit 0ac395c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

common/src/main/java/org/tron/json/JSON.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public final class JSON {
3636
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
3737
// Fastjson Feature.AllowSingleQuotes (default ON)
3838
.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES)
39+
// Partial compatibility with Fastjson Feature.AllowArbitraryCommas:
40+
// this only covers a single trailing comma like {"a":1,} or [1,2,].
41+
// Repeated/arbitrary commas like {"a":1,,,,} and [1,,2] remain rejected.
42+
.enable(JsonReadFeature.ALLOW_TRAILING_COMMA)
3943
// Fastjson accepts a leading plus sign for numbers (for example +123, +0.5)
4044
.enable(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS)
4145
// Partial compatibility for Fastjson's asymmetric decimal behavior:

framework/src/test/java/org/tron/json/JsonTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public void testSingleQuotes() {
3939

4040
@Test
4141
public void testTrailingComma() {
42-
assertThrows(JSONException.class, () -> JSON.parseObject("{\"a\":1,}"));
43-
assertThrows(JSONException.class, () -> JSON.parseArray("[1,2,]"));
42+
assertEquals(1, JSON.parseObject("{\"a\":1,}").getIntValue("a"));
43+
assertEquals(2, JSON.parseArray("[1,2,]").size());
4444
assertThrows(JSONException.class, () -> JSON.parseObject("{c:'NULL',,,,,,}"));
4545
assertThrows(JSONException.class, () -> JSON.parseObject("[1,,2]"));
4646
}

0 commit comments

Comments
 (0)