Skip to content

Commit 340faf5

Browse files
committed
[#73] Avoid String creation using system default charset
Used `StandardCharsets.UTF_8` to create `String` in `JSONParserByteArray` to avoid dependency on system's default charset
1 parent 47a5b02 commit 340faf5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

json-smart/src/main/java/net/minidev/json/parser/JSONParserByteArray.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import net.minidev.json.JSONValue;
2020
import net.minidev.json.writer.JsonReaderI;
2121

22+
import java.nio.charset.Charset;
23+
import java.nio.charset.StandardCharsets;
24+
2225
/**
2326
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
2427
*
@@ -59,7 +62,7 @@ public <T> T parse(byte[] in, JsonReaderI<T> mapper) throws ParseException {
5962
}
6063

6164
protected void extractString(int beginIndex, int endIndex) {
62-
xs = new String(in, beginIndex, endIndex - beginIndex);
65+
xs = new String(in, beginIndex, endIndex - beginIndex, StandardCharsets.UTF_8);
6366
}
6467

6568
protected void extractStringTrim(int start, int stop) {
@@ -71,7 +74,7 @@ protected void extractStringTrim(int start, int stop) {
7174
while ((start < stop) && (val[stop - 1] <= ' ')) {
7275
stop--;
7376
}
74-
xs = new String(in, start, stop - start);
77+
xs = new String(in, start, stop - start, StandardCharsets.UTF_8);
7578
}
7679

7780
protected int indexOf(char c, int pos) {

0 commit comments

Comments
 (0)