mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
Merge pull request #937 from michael-ameri/remove-references
Update JSONParserConfiguration usage in JSONTokener, JSONArray, and JSONObject
This commit is contained in:
commit
8c427d9101
@ -67,12 +67,6 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
*/
|
*/
|
||||||
private final ArrayList<Object> myArrayList;
|
private final ArrayList<Object> myArrayList;
|
||||||
|
|
||||||
// strict mode checks after constructor require access to this object
|
|
||||||
private JSONTokener jsonTokener;
|
|
||||||
|
|
||||||
// strict mode checks after constructor require access to this object
|
|
||||||
private JSONParserConfiguration jsonParserConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an empty JSONArray.
|
* Construct an empty JSONArray.
|
||||||
*/
|
*/
|
||||||
@ -102,14 +96,7 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
if (this.jsonParserConfiguration == null) {
|
boolean isInitial = x.getPrevious() == 0;
|
||||||
this.jsonParserConfiguration = jsonParserConfiguration;
|
|
||||||
}
|
|
||||||
if (this.jsonTokener == null) {
|
|
||||||
this.jsonTokener = x;
|
|
||||||
this.jsonTokener.setJsonParserConfiguration(this.jsonParserConfiguration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x.nextClean() != '[') {
|
if (x.nextClean() != '[') {
|
||||||
throw x.syntaxError("A JSONArray text must start with '['");
|
throw x.syntaxError("A JSONArray text must start with '['");
|
||||||
}
|
}
|
||||||
@ -156,11 +143,19 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
x.back();
|
x.back();
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
|
if (isInitial && jsonParserConfiguration.isStrictMode() &&
|
||||||
|
x.nextClean() != 0) {
|
||||||
|
throw x.syntaxError("Strict mode error: Unparsed characters found at end of input text");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
throw x.syntaxError("Expected a ',' or ']'");
|
throw x.syntaxError("Expected a ',' or ']'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (isInitial && jsonParserConfiguration.isStrictMode() && x.nextClean() != 0) {
|
||||||
|
throw x.syntaxError("Strict mode error: Unparsed characters found at end of input text");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,11 +171,6 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
*/
|
*/
|
||||||
public JSONArray(String source) throws JSONException {
|
public JSONArray(String source) throws JSONException {
|
||||||
this(source, new JSONParserConfiguration());
|
this(source, new JSONParserConfiguration());
|
||||||
// Strict mode does not allow trailing chars
|
|
||||||
if (this.jsonParserConfiguration.isStrictMode() &&
|
|
||||||
this.jsonTokener.nextClean() != 0) {
|
|
||||||
throw jsonTokener.syntaxError("Strict mode error: Unparsed characters found at end of input text");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,12 +185,7 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
* If there is a syntax error.
|
* If there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public JSONArray(String source, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
public JSONArray(String source, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
||||||
this(new JSONTokener(source), jsonParserConfiguration);
|
this(new JSONTokener(source, jsonParserConfiguration), jsonParserConfiguration);
|
||||||
// Strict mode does not allow trailing chars
|
|
||||||
if (this.jsonParserConfiguration.isStrictMode() &&
|
|
||||||
this.jsonTokener.nextClean() != 0) {
|
|
||||||
throw jsonTokener.syntaxError("Strict mode error: Unparsed characters found at end of input text");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,12 +152,6 @@ public class JSONObject {
|
|||||||
*/
|
*/
|
||||||
public static final Object NULL = new Null();
|
public static final Object NULL = new Null();
|
||||||
|
|
||||||
// strict mode checks after constructor require access to this object
|
|
||||||
private JSONTokener jsonTokener;
|
|
||||||
|
|
||||||
// strict mode checks after constructor require access to this object
|
|
||||||
private JSONParserConfiguration jsonParserConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an empty JSONObject.
|
* Construct an empty JSONObject.
|
||||||
*/
|
*/
|
||||||
@ -217,18 +211,11 @@ public class JSONObject {
|
|||||||
*/
|
*/
|
||||||
public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
if (this.jsonParserConfiguration == null) {
|
|
||||||
this.jsonParserConfiguration = jsonParserConfiguration;
|
|
||||||
}
|
|
||||||
if (this.jsonTokener == null) {
|
|
||||||
this.jsonTokener = x;
|
|
||||||
this.jsonTokener.setJsonParserConfiguration(this.jsonParserConfiguration);
|
|
||||||
}
|
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
String key;
|
String key;
|
||||||
|
|
||||||
|
boolean isInitial = x.getPrevious() == 0;
|
||||||
|
|
||||||
if (x.nextClean() != '{') {
|
if (x.nextClean() != '{') {
|
||||||
throw x.syntaxError("A JSONObject text must begin with '{'");
|
throw x.syntaxError("A JSONObject text must begin with '{'");
|
||||||
}
|
}
|
||||||
@ -238,6 +225,9 @@ public class JSONObject {
|
|||||||
case 0:
|
case 0:
|
||||||
throw x.syntaxError("A JSONObject text must end with '}'");
|
throw x.syntaxError("A JSONObject text must end with '}'");
|
||||||
case '}':
|
case '}':
|
||||||
|
if (isInitial && jsonParserConfiguration.isStrictMode() && x.nextClean() != 0) {
|
||||||
|
throw x.syntaxError("Strict mode error: Unparsed characters found at end of input text");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
key = x.nextSimpleValue(c).toString();
|
key = x.nextSimpleValue(c).toString();
|
||||||
@ -288,6 +278,9 @@ public class JSONObject {
|
|||||||
x.back();
|
x.back();
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
|
if (isInitial && jsonParserConfiguration.isStrictMode() && x.nextClean() != 0) {
|
||||||
|
throw x.syntaxError("Strict mode error: Unparsed characters found at end of input text");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
throw x.syntaxError("Expected a ',' or '}'");
|
throw x.syntaxError("Expected a ',' or '}'");
|
||||||
@ -456,11 +449,6 @@ public class JSONObject {
|
|||||||
*/
|
*/
|
||||||
public JSONObject(String source) throws JSONException {
|
public JSONObject(String source) throws JSONException {
|
||||||
this(source, new JSONParserConfiguration());
|
this(source, new JSONParserConfiguration());
|
||||||
// Strict mode does not allow trailing chars
|
|
||||||
if (this.jsonParserConfiguration.isStrictMode() &&
|
|
||||||
this.jsonTokener.nextClean() != 0) {
|
|
||||||
throw new JSONException("Strict mode error: Unparsed characters found at end of input text");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -478,12 +466,7 @@ public class JSONObject {
|
|||||||
* duplicated key.
|
* duplicated key.
|
||||||
*/
|
*/
|
||||||
public JSONObject(String source, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
public JSONObject(String source, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
|
||||||
this(new JSONTokener(source), jsonParserConfiguration);
|
this(new JSONTokener(source, jsonParserConfiguration), jsonParserConfiguration);
|
||||||
// Strict mode does not allow trailing chars
|
|
||||||
if (this.jsonParserConfiguration.isStrictMode() &&
|
|
||||||
this.jsonTokener.nextClean() != 0) {
|
|
||||||
throw new JSONException("Strict mode error: Unparsed characters found at end of input text");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,8 @@ public class JSONTokener {
|
|||||||
*
|
*
|
||||||
* @param reader A reader.
|
* @param reader A reader.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(Reader reader) {
|
public JSONTokener(Reader reader, JSONParserConfiguration jsonParserConfiguration) {
|
||||||
|
this.jsonParserConfiguration = jsonParserConfiguration;
|
||||||
this.reader = reader.markSupported()
|
this.reader = reader.markSupported()
|
||||||
? reader
|
? reader
|
||||||
: new BufferedReader(reader);
|
: new BufferedReader(reader);
|
||||||
@ -53,13 +54,24 @@ public class JSONTokener {
|
|||||||
this.line = 1;
|
this.line = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONTokener(Reader reader) {
|
||||||
|
this(reader, new JSONParserConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a JSONTokener from an InputStream. The caller must close the input stream.
|
* Construct a JSONTokener from an InputStream. The caller must close the input stream.
|
||||||
* @param inputStream The source.
|
* @param inputStream The source.
|
||||||
*/
|
*/
|
||||||
public JSONTokener(InputStream inputStream) {
|
public JSONTokener(InputStream inputStream) {
|
||||||
this(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
|
this(inputStream, new JSONParserConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a JSONTokener from an InputStream. The caller must close the input stream.
|
||||||
|
* @param inputStream The source.
|
||||||
|
*/
|
||||||
|
public JSONTokener(InputStream inputStream, JSONParserConfiguration jsonParserConfiguration) {
|
||||||
|
this(new InputStreamReader(inputStream, Charset.forName("UTF-8")),jsonParserConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +84,10 @@ public class JSONTokener {
|
|||||||
this(new StringReader(s));
|
this(new StringReader(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONTokener(String s, JSONParserConfiguration jsonParserConfiguration) {
|
||||||
|
this(new StringReader(s), jsonParserConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter
|
* Getter
|
||||||
* @return jsonParserConfiguration
|
* @return jsonParserConfiguration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user