Skip to content

Commit

Permalink
fix json skipValue error, for issue #1257
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 29, 2024
1 parent 7adaad2 commit 2ab21f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,11 @@ public void skipValue() {
return;
}

if (type >= BC_INT32_SHORT_MIN && type <= BC_INT32_SHORT_MAX) {
offset += 2;
return;
}

if (type >= BC_STR_ASCII_FIX_MIN && type <= BC_STR_ASCII_FIX_MAX) {
offset += (type - BC_STR_ASCII_FIX_MIN);
return;
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/jsonb/SkipTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ public void test_0() {
assertNotNull(a);
}

@Test
public void test_1() {
for (int i = 0; i < 100; i += 10) {
byte[] jsonbBytes = JSONObject.of("v", (byte) i).toJSONBBytes();
A a = JSONB.parseObject(jsonbBytes, A.class);
assertNotNull(a);
}

for (int i = 0; i < 1000; i += 10) {
byte[] jsonbBytes = JSONObject.of("v", (short) i).toJSONBBytes();
A a = JSONB.parseObject(jsonbBytes, A.class);
assertNotNull(a);
}

for (int i = 0; i < 100000; i += 10) {
byte[] jsonbBytes = JSONObject.of("v", i).toJSONBBytes();
A a = JSONB.parseObject(jsonbBytes, A.class);
assertNotNull(a);
}

for (int i = 0; i < 100000; i += 10) {
byte[] jsonbBytes = JSONObject.of("v", (long) i).toJSONBBytes();
A a = JSONB.parseObject(jsonbBytes, A.class);
assertNotNull(a);
}
}

public static class A {
}
}

0 comments on commit 2ab21f1

Please sign in to comment.