Skip to content

Commit 0771b92

Browse files
committed
fix #144, parse max int/long
1 parent 5a573f2 commit 0771b92

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/com/jsoniter/IterImplForStreaming.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static long readLongSlowPath(JsonIterator iter, long value) throws IOException {
481481
// overflow
482482
if (value == Long.MIN_VALUE) {
483483
// if there is more number following, subsequent read will fail anyway
484-
iter.head = i;
484+
iter.head = i + 1;
485485
return value;
486486
} else {
487487
throw iter.reportError("readPositiveLong", "value is too large for long");
@@ -508,7 +508,7 @@ static int readIntSlowPath(JsonIterator iter, int value) throws IOException {
508508
// overflow
509509
if (value == Integer.MIN_VALUE) {
510510
// if there is more number following, subsequent read will fail anyway
511-
iter.head = i;
511+
iter.head = i + 1;
512512
return value;
513513
} else {
514514
throw iter.reportError("readPositiveInt", "value is too large for int");

src/test/java/com/jsoniter/TestInteger.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public void test_leading_zero() throws IOException {
9494
}
9595
}
9696

97+
public void test_max_int() throws IOException {
98+
int[] ints = JsonIterator.deserialize("[2147483647,-2147483648]", int[].class);
99+
assertEquals(Integer.MAX_VALUE, ints[0]);
100+
assertEquals(Integer.MIN_VALUE, ints[1]);
101+
}
102+
97103
private int parseInt(String input) throws IOException {
98104
if (isStreaming) {
99105
JsonIterator iter = JsonIterator.parse(new ByteArrayInputStream(input.getBytes()), 2);

0 commit comments

Comments
 (0)