diff --git a/spring-boot-tools/spring-boot-configuration-processor/pom.xml b/spring-boot-tools/spring-boot-configuration-processor/pom.xml
index c2bb79e469e1..965468403ea8 100644
--- a/spring-boot-tools/spring-boot-configuration-processor/pom.xml
+++ b/spring-boot-tools/spring-boot-configuration-processor/pom.xml
@@ -40,6 +40,24 @@
{@code JSONArray} has the same type coercion behavior and - * optional/mandatory accessors as {@link JSONObject}. See that class' - * documentation for details. - * - *
Warning: this class represents null in two incompatible - * ways: the standard Java {@code null} reference, and the sentinel value {@link - * JSONObject#NULL}. In particular, {@code get} fails if the requested index - * holds the null reference, but succeeds if it holds {@code JSONObject.NULL}. - * - *
Instances of this class are not thread safe. Although this class is - * nonfinal, it was not designed for inheritance and should not be subclassed. - * In particular, self-use by overridable methods is not specified. See - * Effective Java Item 17, "Design and Document or inheritance or else - * prohibit it" for further information. + * A dense indexed sequence of values. Values may be any mix of {@link JSONObject + * JSONObjects}, other {@link JSONArray JSONArrays}, Strings, Booleans, Integers, Longs, + * Doubles, {@code null} or {@link JSONObject#NULL}. Values may not be + * {@link Double#isNaN() NaNs}, {@link Double#isInfinite() infinities}, or of any type not + * listed here. + *
+ * {@code JSONArray} has the same type coercion behavior and optional/mandatory accessors + * as {@link JSONObject}. See that class' documentation for details. + *
+ * Warning: this class represents null in two incompatible ways: the + * standard Java {@code null} reference, and the sentinel value {@link JSONObject#NULL}. + * In particular, {@code get} fails if the requested index holds the null reference, but + * succeeds if it holds {@code JSONObject.NULL}. + *
+ * Instances of this class are not thread safe. Although this class is nonfinal, it was + * not designed for inheritance and should not be subclassed. In particular, self-use by + * overridable methods is not specified. See Effective Java Item 17, "Design and + * Document or inheritance or else prohibit it" for further information. */ public class JSONArray { @@ -58,37 +56,31 @@ public JSONArray() { } /** - * Creates a new {@code JSONArray} by copying all values from the given - * collection. - * - * @param copyFrom a collection whose values are of supported types. - * Unsupported values are not permitted and will yield an array in an - * inconsistent state. + * Creates a new {@code JSONArray} by copying all values from the given collection. + * @param copyFrom a collection whose values are of supported types. Unsupported + * values are not permitted and will yield an array in an inconsistent state. */ /* Accept a raw type for API compatibility */ + @SuppressWarnings("rawtypes") public JSONArray(Collection copyFrom) { this(); if (copyFrom != null) { - for (Iterator it = copyFrom.iterator(); it.hasNext(); ) { + for (Iterator it = copyFrom.iterator(); it.hasNext();) { put(JSONObject.wrap(it.next())); } } } /** - * Creates a new {@code JSONArray} with values from the next array in the - * tokener. - * - * @param readFrom a tokener whose nextValue() method will yield a - * {@code JSONArray}. - * @throws JSONException if the parse fails or doesn't yield a - * {@code JSONArray}. + * Creates a new {@code JSONArray} with values from the next array in the tokener. + * @param readFrom a tokener whose nextValue() method will yield a {@code JSONArray}. + * @throws JSONException if the parse fails or doesn't yield a {@code JSONArray}. * @throws JSONException if processing of json failed */ public JSONArray(JSONTokener readFrom) throws JSONException { /* - * Getting the parser to populate this could get tricky. Instead, just - * parse to temporary JSONArray and then steal the data from that. + * Getting the parser to populate this could get tricky. Instead, just parse to + * temporary JSONArray and then steal the data from that. */ Object object = readFrom.nextValue(); if (object instanceof JSONArray) { @@ -101,7 +93,6 @@ public JSONArray(JSONTokener readFrom) throws JSONException { /** * Creates a new {@code JSONArray} with values from the JSON string. - * * @param json a JSON-encoded string containing an array. * @throws JSONException if the parse fails or doesn't yield a {@code * JSONArray}. @@ -149,7 +140,7 @@ public JSONArray put(boolean value) { * Appends {@code value} to the end of this array. * * @param value a finite value. May not be {@link Double#isNaN() NaNs} or - * {@link Double#isInfinite() infinities}. + * {@link Double#isInfinite() infinities}. * @return this array. * @throws JSONException if processing of json failed */ @@ -181,11 +172,10 @@ public JSONArray put(long value) { /** * Appends {@code value} to the end of this array. * - * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, - * Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May - * not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite() - * infinities}. Unsupported values are not permitted and will cause the - * array to be in an inconsistent state. + * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, + * Long, Double, {@link JSONObject#NULL}, or {@code null}. May not be + * {@link Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}. Unsupported + * values are not permitted and will cause the array to be in an inconsistent state. * @return this array. */ public JSONArray put(Object value) { @@ -194,8 +184,8 @@ public JSONArray put(Object value) { } /** - * Sets the value at {@code index} to {@code value}, null padding this array - * to the required length if necessary. If a value already exists at {@code + * Sets the value at {@code index} to {@code value}, null padding this array to the + * required length if necessary. If a value already exists at {@code * index}, it will be replaced. * @param index the index to set the value to * @param value the value @@ -207,12 +197,12 @@ public JSONArray put(int index, boolean value) throws JSONException { } /** - * Sets the value at {@code index} to {@code value}, null padding this array - * to the required length if necessary. If a value already exists at {@code + * Sets the value at {@code index} to {@code value}, null padding this array to the + * required length if necessary. If a value already exists at {@code * index}, it will be replaced. * @param index the index to set the value to * @param value a finite value. May not be {@link Double#isNaN() NaNs} or - * {@link Double#isInfinite() infinities}. + * {@link Double#isInfinite() infinities}. * @return this array. * @throws JSONException if processing of json failed */ @@ -221,8 +211,8 @@ public JSONArray put(int index, double value) throws JSONException { } /** - * Sets the value at {@code index} to {@code value}, null padding this array - * to the required length if necessary. If a value already exists at {@code + * Sets the value at {@code index} to {@code value}, null padding this array to the + * required length if necessary. If a value already exists at {@code * index}, it will be replaced. * @param index the index to set the value to * @param value the value @@ -234,8 +224,8 @@ public JSONArray put(int index, int value) throws JSONException { } /** - * Sets the value at {@code index} to {@code value}, null padding this array - * to the required length if necessary. If a value already exists at {@code + * Sets the value at {@code index} to {@code value}, null padding this array to the + * required length if necessary. If a value already exists at {@code * index}, it will be replaced. * @param index the index to set the value to * @param value the value @@ -247,20 +237,20 @@ public JSONArray put(int index, long value) throws JSONException { } /** - * Sets the value at {@code index} to {@code value}, null padding this array - * to the required length if necessary. If a value already exists at {@code + * Sets the value at {@code index} to {@code value}, null padding this array to the + * required length if necessary. If a value already exists at {@code * index}, it will be replaced. * @param index the index to set the value to - * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, - * Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May - * not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite() - * infinities}. + * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, + * Long, Double, {@link JSONObject#NULL}, or {@code null}. May not be + * {@link Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}. * @return this array. * @throws JSONException if processing of json failed */ public JSONArray put(int index, Object value) throws JSONException { if (value instanceof Number) { - // deviate from the original by checking all Numbers, not just floats & doubles + // deviate from the original by checking all Numbers, not just floats & + // doubles JSON.checkDouble(((Number) value).doubleValue()); } while (this.values.size() <= index) { @@ -271,8 +261,8 @@ public JSONArray put(int index, Object value) throws JSONException { } /** - * Returns true if this array has no value at {@code index}, or if its value - * is the {@code null} reference or {@link JSONObject#NULL}. + * Returns true if this array has no value at {@code index}, or if its value is the + * {@code null} reference or {@link JSONObject#NULL}. * @param index the index to set the value to * @return true if this array has no value at {@code index} */ @@ -285,9 +275,9 @@ public boolean isNull(int index) { * Returns the value at {@code index}. * @param index the index to get the value from * @return the value at {@code index}. - * @throws JSONException if this array has no value at {@code index}, or if - * that value is the {@code null} reference. This method returns - * normally if the value is {@code JSONObject#NULL}. + * @throws JSONException if this array has no value at {@code index}, or if that value + * is the {@code null} reference. This method returns normally if the value is + * {@code JSONObject#NULL}. */ public Object get(int index) throws JSONException { try { @@ -298,13 +288,14 @@ public Object get(int index) throws JSONException { return value; } catch (IndexOutOfBoundsException e) { - throw new JSONException("Index " + index + " out of range [0.." + this.values.size() + ")"); + throw new JSONException( + "Index " + index + " out of range [0.." + this.values.size() + ")"); } } /** - * Returns the value at {@code index}, or null if the array has no value - * at {@code index}. + * Returns the value at {@code index}, or null if the array has no value at + * {@code index}. * @param index the index to get the value from * @return the value at {@code index} or {@code null} */ @@ -329,12 +320,12 @@ public Object remove(int index) { } /** - * Returns the value at {@code index} if it exists and is a boolean or can - * be coerced to a boolean. + * Returns the value at {@code index} if it exists and is a boolean or can be coerced + * to a boolean. * @param index the index to get the value from * @return the value at {@code index} - * @throws JSONException if the value at {@code index} doesn't exist or - * cannot be coerced to a boolean. + * @throws JSONException if the value at {@code index} doesn't exist or cannot be + * coerced to a boolean. */ public boolean getBoolean(int index) throws JSONException { Object object = get(index); @@ -346,8 +337,8 @@ public boolean getBoolean(int index) throws JSONException { } /** - * Returns the value at {@code index} if it exists and is a boolean or can - * be coerced to a boolean. Returns false otherwise. + * Returns the value at {@code index} if it exists and is a boolean or can be coerced + * to a boolean. Returns false otherwise. * @param index the index to get the value from * @return the {@code value} or {@code false} */ @@ -356,8 +347,8 @@ public boolean optBoolean(int index) { } /** - * Returns the value at {@code index} if it exists and is a boolean or can - * be coerced to a boolean. Returns {@code fallback} otherwise. + * Returns the value at {@code index} if it exists and is a boolean or can be coerced + * to a boolean. Returns {@code fallback} otherwise. * @param index the index to get the value from * @param fallback the fallback value * @return the value at {@code index} of {@code fallback} @@ -369,12 +360,12 @@ public boolean optBoolean(int index, boolean fallback) { } /** - * Returns the value at {@code index} if it exists and is a double or can - * be coerced to a double. + * Returns the value at {@code index} if it exists and is a double or can be coerced + * to a double. * @param index the index to get the value from * @return the {@code value} - * @throws JSONException if the value at {@code index} doesn't exist or - * cannot be coerced to a double. + * @throws JSONException if the value at {@code index} doesn't exist or cannot be + * coerced to a double. */ public double getDouble(int index) throws JSONException { Object object = get(index); @@ -386,8 +377,8 @@ public double getDouble(int index) throws JSONException { } /** - * Returns the value at {@code index} if it exists and is a double or can - * be coerced to a double. Returns {@code NaN} otherwise. + * Returns the value at {@code index} if it exists and is a double or can be coerced + * to a double. Returns {@code NaN} otherwise. * @param index the index to get the value from * @return the {@code value} or {@code NaN} */ @@ -396,8 +387,8 @@ public double optDouble(int index) { } /** - * Returns the value at {@code index} if it exists and is a double or can - * be coerced to a double. Returns {@code fallback} otherwise. + * Returns the value at {@code index} if it exists and is a double or can be coerced + * to a double. Returns {@code fallback} otherwise. * @param index the index to get the value from * @param fallback the fallback value * @return the value at {@code index} of {@code fallback} @@ -409,12 +400,12 @@ public double optDouble(int index, double fallback) { } /** - * Returns the value at {@code index} if it exists and is an int or - * can be coerced to an int. + * Returns the value at {@code index} if it exists and is an int or can be coerced to + * an int. * @param index the index to get the value from * @return the {@code value} - * @throws JSONException if the value at {@code index} doesn't exist or - * cannot be coerced to a int. + * @throws JSONException if the value at {@code index} doesn't exist or cannot be + * coerced to a int. */ public int getInt(int index) throws JSONException { Object object = get(index); @@ -426,8 +417,8 @@ public int getInt(int index) throws JSONException { } /** - * Returns the value at {@code index} if it exists and is an int or - * can be coerced to an int. Returns 0 otherwise. + * Returns the value at {@code index} if it exists and is an int or can be coerced to + * an int. Returns 0 otherwise. * @param index the index to get the value from * @return the {@code value} or {@code 0} */ @@ -436,8 +427,8 @@ public int optInt(int index) { } /** - * Returns the value at {@code index} if it exists and is an int or - * can be coerced to an int. Returns {@code fallback} otherwise. + * Returns the value at {@code index} if it exists and is an int or can be coerced to + * an int. Returns {@code fallback} otherwise. * @param index the index to get the value from * @param fallback the fallback value * @return the value at {@code index} of {@code fallback} @@ -449,13 +440,13 @@ public int optInt(int index, int fallback) { } /** - * Returns the value at {@code index} if it exists and is a long or - * can be coerced to a long. + * Returns the value at {@code index} if it exists and is a long or can be coerced to + * a long. * @param index the index to get the value from * @return the {@code value} * - * @throws JSONException if the value at {@code index} doesn't exist or - * cannot be coerced to a long. + * @throws JSONException if the value at {@code index} doesn't exist or cannot be + * coerced to a long. */ public long getLong(int index) throws JSONException { Object object = get(index); @@ -467,8 +458,8 @@ public long getLong(int index) throws JSONException { } /** - * Returns the value at {@code index} if it exists and is a long or - * can be coerced to a long. Returns 0 otherwise. + * Returns the value at {@code index} if it exists and is a long or can be coerced to + * a long. Returns 0 otherwise. * @param index the index to get the value from * @return the {@code value} or {@code 0} */ @@ -477,8 +468,8 @@ public long optLong(int index) { } /** - * Returns the value at {@code index} if it exists and is a long or - * can be coerced to a long. Returns {@code fallback} otherwise. + * Returns the value at {@code index} if it exists and is a long or can be coerced to + * a long. Returns {@code fallback} otherwise. * @param index the index to get the value from * @param fallback the fallback value * @return the value at {@code index} of {@code fallback} @@ -490,8 +481,7 @@ public long optLong(int index, long fallback) { } /** - * Returns the value at {@code index} if it exists, coercing it if - * necessary. + * Returns the value at {@code index} if it exists, coercing it if necessary. * @param index the index to get the value from * @return the {@code value} * @throws JSONException if no such value exists. @@ -506,8 +496,8 @@ public String getString(int index) throws JSONException { } /** - * Returns the value at {@code index} if it exists, coercing it if - * necessary. Returns the empty string if no such value exists. + * Returns the value at {@code index} if it exists, coercing it if necessary. Returns + * the empty string if no such value exists. * @param index the index to get the value from * @return the {@code value} or an empty string */ @@ -516,8 +506,8 @@ public String optString(int index) { } /** - * Returns the value at {@code index} if it exists, coercing it if - * necessary. Returns {@code fallback} if no such value exists. + * Returns the value at {@code index} if it exists, coercing it if necessary. Returns + * {@code fallback} if no such value exists. * @param index the index to get the value from * @param fallback the fallback value * @return the value at {@code index} of {@code fallback} @@ -587,11 +577,10 @@ public JSONObject optJSONObject(int index) { } /** - * Returns a new object whose values are the values in this array, and whose - * names are the values in {@code names}. Names and values are paired up by - * index from 0 through to the shorter array's length. Names that are not - * strings will be coerced to strings. This method returns null if either - * array is empty. + * Returns a new object whose values are the values in this array, and whose names are + * the values in {@code names}. Names and values are paired up by index from 0 through + * to the shorter array's length. Names that are not strings will be coerced to + * strings. This method returns null if either array is empty. * @param names the property names * @return a json object * @throws JSONException if processing of json failed @@ -611,10 +600,9 @@ public JSONObject toJSONObject(JSONArray names) throws JSONException { /** * Returns a new string by alternating this array's values with {@code - * separator}. This array's string values are quoted and have their special - * characters escaped. For example, the array containing the strings '12" - * pizza', 'taco' and 'soda' joined on '+' returns this: - *
"12\" pizza"+"taco"+"soda"+ * separator}. This array's string values are quoted and have their special characters + * escaped. For example, the array containing the strings '12" pizza', 'taco' and + * 'soda' joined on '+' returns this:
"12\" pizza"+"taco"+"soda"* @param separator the separator to use * @return the joined value * @throws JSONException if processing of json failed @@ -633,8 +621,7 @@ public String join(String separator) throws JSONException { } /** - * Encodes this array as a compact JSON string, such as: - *
[94043,90210]+ * Encodes this array as a compact JSON string, such as:
[94043,90210]* @return a compact JSON string representation of this array */ @Override @@ -650,16 +637,13 @@ public String toString() { } /** - * Encodes this array as a human readable JSON string for debugging, such - * as: - *
+ * Encodes this array as a human readable JSON string for debugging, such as:* [ * 94043, * 90210 * ]* - * @param indentSpaces the number of spaces to indent for each level of - * nesting. + * @param indentSpaces the number of spaces to indent for each level of nesting. * @return a human readable JSON string of this array * @throws JSONException if processing of json failed */ @@ -687,4 +671,5 @@ public int hashCode() { // diverge from the original, which doesn't implement hashCode return this.values.hashCode(); } + } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONException.java b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONException.java similarity index 67% rename from spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONException.java rename to spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONException.java index d9806b650557..b90362dae968 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONException.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONException.java @@ -21,18 +21,17 @@ /** * Thrown to indicate a problem with the JSON API. Such problems include: *
Although this is a checked exception, it is rarely recoverable. Most - * callers should simply wrap this exception in an unchecked exception and - * rethrow: - *
public JSONArray toJSONObject() { + *+ * Although this is a checked exception, it is rarely recoverable. Most callers should + * simply wrap this exception in an unchecked exception and rethrow:
+ * public JSONArray toJSONObject() { * try { * JSONObject result = new JSONObject(); * ... @@ -46,4 +45,5 @@ public class JSONException extends Exception { public JSONException(String s) { super(s); } + } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONObject.java b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java similarity index 70% rename from spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONObject.java rename to spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java index ed3f9e8b7d95..c3c816e53031 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONObject.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java @@ -25,56 +25,52 @@ // Note: this class was written without inspecting the non-free org.json sourcecode. /** - * A modifiable set of name/value mappings. Names are unique, non-null strings. - * Values may be any mix of {@link JSONObject JSONObjects}, {@link JSONArray - * JSONArrays}, Strings, Booleans, Integers, Longs, Doubles or {@link #NULL}. - * Values may not be {@code null}, {@link Double#isNaN() NaNs}, {@link - * Double#isInfinite() infinities}, or of any type not listed here. - * - *This class can coerce values to another type when requested. + * A modifiable set of name/value mappings. Names are unique, non-null strings. Values may + * be any mix of {@link JSONObject JSONObjects}, {@link JSONArray JSONArrays}, Strings, + * Booleans, Integers, Longs, Doubles or {@link #NULL}. Values may not be {@code null}, + * {@link Double#isNaN() NaNs}, {@link Double#isInfinite() infinities}, or of any type not + * listed here. + *
+ * This class can coerce values to another type when requested. *
This class can look up both mandatory and optional values: + *
+ * This class can look up both mandatory and optional values: *
getType()
to retrieve a mandatory value. This
- * fails with a {@code JSONException} if the requested name has no value
- * or if the value cannot be coerced to the requested type.
- * optType()
to retrieve an optional value. This
- * returns a system- or user-supplied default if the requested name has no
- * value or if the value cannot be coerced to the requested type.
+ * getType()
to retrieve a mandatory value. This fails with a
+ * {@code JSONException} if the requested name has no value or if the value cannot be
+ * coerced to the requested type.
+ * optType()
to retrieve an optional value. This returns a
+ * system- or user-supplied default if the requested name has no value or if the value
+ * cannot be coerced to the requested type.
* Warning: this class represents null in two incompatible - * ways: the standard Java {@code null} reference, and the sentinel value {@link - * JSONObject#NULL}. In particular, calling {@code put(name, null)} removes the - * named entry from the object but {@code put(name, JSONObject.NULL)} stores an - * entry whose value is {@code JSONObject.NULL}. - * - *
Instances of this class are not thread safe. Although this class is - * nonfinal, it was not designed for inheritance and should not be subclassed. - * In particular, self-use by overrideable methods is not specified. See - * Effective Java Item 17, "Design and Document or inheritance or else - * prohibit it" for further information. + *
+ * Warning: this class represents null in two incompatible ways: the + * standard Java {@code null} reference, and the sentinel value {@link JSONObject#NULL}. + * In particular, calling {@code put(name, null)} removes the named entry from the object + * but {@code put(name, JSONObject.NULL)} stores an entry whose value is + * {@code JSONObject.NULL}. + *
+ * Instances of this class are not thread safe. Although this class is nonfinal, it was + * not designed for inheritance and should not be subclassed. In particular, self-use by + * overrideable methods is not specified. See Effective Java Item 17, "Design and + * Document or inheritance or else prohibit it" for further information. */ public class JSONObject { @@ -84,27 +80,29 @@ public class JSONObject { * A sentinel value used to explicitly define a name with no value. Unlike * {@code null}, names with this value: *
This value violates the general contract of {@link Object#equals} by - * returning true when compared to {@code null}. Its {@link #toString} - * method returns "null". + *
+ * This value violates the general contract of {@link Object#equals} by returning true
+ * when compared to {@code null}. Its {@link #toString} method returns "null".
*/
public static final Object NULL = new Object() {
+
@Override
public boolean equals(Object o) {
- return o == this || o == null; // API specifies this broken equals implementation
+ return o == this || o == null; // API specifies this broken equals
+ // implementation
}
@Override
public String toString() {
return "null";
}
+
};
private final Map If the object is null or , returns {@link #NULL}.
- * If the object is a {@code JSONArray} or {@code JSONObject}, no wrapping is necessary.
- * If the object is {@code NULL}, no wrapping is necessary.
- * If the object is an array or {@code Collection}, returns an equivalent {@code JSONArray}.
- * If the object is a {@code Map}, returns an equivalent {@code JSONObject}.
- * If the object is a primitive wrapper type or {@code String}, returns the object.
- * Otherwise if the object is from a {@code java} package, returns the result of {@code toString}.
- * If wrapping fails, returns null.
+ *
+ * If the object is null or , returns {@link #NULL}. If the object is a
+ * {@code JSONArray} or {@code JSONObject}, no wrapping is necessary. If the object is
+ * {@code NULL}, no wrapping is necessary. If the object is an array or
+ * {@code Collection}, returns an equivalent {@code JSONArray}. If the object is a
+ * {@code Map}, returns an equivalent {@code JSONObject}. If the object is a primitive
+ * wrapper type or {@code String}, returns the object. Otherwise if the object is from
+ * a {@code java} package, returns the result of {@code toString}. If wrapping fails,
+ * returns null.
* @param o the object to wrap
* @return the wrapped object
*/
+ @SuppressWarnings("rawtypes")
public static Object wrap(Object o) {
if (o == null) {
return NULL;
@@ -847,15 +823,9 @@ else if (o.getClass().isArray()) {
if (o instanceof Map) {
return new JSONObject((Map) o);
}
- if (o instanceof Boolean ||
- o instanceof Byte ||
- o instanceof Character ||
- o instanceof Double ||
- o instanceof Float ||
- o instanceof Integer ||
- o instanceof Long ||
- o instanceof Short ||
- o instanceof String) {
+ if (o instanceof Boolean || o instanceof Byte || o instanceof Character
+ || o instanceof Double || o instanceof Float || o instanceof Integer
+ || o instanceof Long || o instanceof Short || o instanceof String) {
return o;
}
if (o.getClass().getPackage().getName().startsWith("java.")) {
@@ -866,4 +836,5 @@ else if (o.getClass().isArray()) {
}
return null;
}
+
}
diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java
similarity index 72%
rename from spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java
rename to spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java
index 7269ece1e80b..69ccc6d8fbc7 100644
--- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java
+++ b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java
@@ -23,80 +23,77 @@
// Note: this class was written without inspecting the non-free org.json sourcecode.
/**
- * Implements {@link JSONObject#toString} and {@link JSONArray#toString}. Most
- * application developers should use those methods directly and disregard this
- * API. For example: Stringers only encode well-formed JSON strings. In particular:
+ *
+ * Stringers only encode well-formed JSON strings. In particular:
* This class provides no facility for pretty-printing (ie. indenting)
- * output. To encode indented output, use {@link JSONObject#toString(int)} or
+ *
+ * This class provides no facility for pretty-printing (ie. indenting) output. To encode
+ * indented output, use {@link JSONObject#toString(int)} or
* {@link JSONArray#toString(int)}.
- *
- * Some implementations of the API support at most 20 levels of nesting.
- * Attempts to create more than 20 levels of nesting may fail with a {@link
- * JSONException}.
- *
- * Each stringer may be used to encode a single top level value. Instances of
- * this class are not thread safe. Although this class is nonfinal, it was not
- * designed for inheritance and should not be subclassed. In particular,
- * self-use by overrideable methods is not specified. See Effective Java
- * Item 17, "Design and Document or inheritance or else prohibit it" for further
- * information.
+ *
+ * Some implementations of the API support at most 20 levels of nesting. Attempts to
+ * create more than 20 levels of nesting may fail with a {@link JSONException}.
+ *
+ * Each stringer may be used to encode a single top level value. Instances of this class
+ * are not thread safe. Although this class is nonfinal, it was not designed for
+ * inheritance and should not be subclassed. In particular, self-use by overrideable
+ * methods is not specified. See Effective Java Item 17,
+ * "Design and Document or inheritance or else prohibit it" for further information.
*/
public class JSONStringer {
- /** The output data, containing at most one top-level array or object. */
+ /**
+ * The output data, containing at most one top-level array or object.
+ */
final StringBuilder out = new StringBuilder();
/**
- * Lexical scoping elements within this stringer, necessary to insert the
- * appropriate separator characters (ie. commas and colons) and to detect
- * nesting errors.
+ * Lexical scoping elements within this stringer, necessary to insert the appropriate
+ * separator characters (ie. commas and colons) and to detect nesting errors.
*/
enum Scope {
/**
- * An array with no elements requires no separators or newlines before
- * it is closed.
+ * An array with no elements requires no separators or newlines before it is
+ * closed.
*/
EMPTY_ARRAY,
/**
- * A array with at least one value requires a comma and newline before
- * the next element.
+ * A array with at least one value requires a comma and newline before the next
+ * element.
*/
NONEMPTY_ARRAY,
/**
- * An object with no keys or values requires no separators or newlines
- * before it is closed.
+ * An object with no keys or values requires no separators or newlines before it
+ * is closed.
*/
EMPTY_OBJECT,
/**
- * An object whose most recent element is a key. The next element must
- * be a value.
+ * An object whose most recent element is a key. The next element must be a value.
*/
DANGLING_KEY,
/**
- * An object with at least one name/value pair requires a comma and
- * newline before the next element.
+ * An object with at least one name/value pair requires a comma and newline before
+ * the next element.
*/
NONEMPTY_OBJECT,
@@ -104,18 +101,19 @@ enum Scope {
* A special bracketless array needed by JSONStringer.join() and
* JSONObject.quote() only. Not used for JSON encoding.
*/
- NULL,
+ NULL
+
}
/**
- * Unlike the original implementation, this stack isn't limited to 20
- * levels of nesting.
+ * Unlike the original implementation, this stack isn't limited to 20 levels of
+ * nesting.
*/
private final List If invoked with unterminated arrays or unclosed objects, this method's
- * return value is undefined.
- *
- * Warning: although it contradicts the general contract
- * of {@link Object#toString}, this method returns null if the stringer
- * contains no data.
+ *
+ * If invoked with unterminated arrays or unclosed objects, this method's return value
+ * is undefined.
+ *
+ * Warning: although it contradicts the general contract of
+ * {@link Object#toString}, this method returns null if the stringer contains no data.
* @return the encoded JSON string.
*/
@Override
public String toString() {
return this.out.length() == 0 ? null : this.out.toString();
}
+
}
diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java
similarity index 63%
rename from spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java
rename to spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java
index b54fc6b617d8..ea98a4e0fbf1 100644
--- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java
+++ b/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java
@@ -19,10 +19,10 @@
// Note: this class was written without inspecting the non-free org.json sourcecode.
/**
- * Parses a JSON (RFC 4627)
- * encoded string into the corresponding object. Most clients of
- * this class will use only need the {@link #JSONTokener(String) constructor}
- * and {@link #nextValue} method. Example usage: For best interoperability and performance use JSON that complies with
- * RFC 4627, such as that generated by {@link JSONStringer}. For legacy reasons
- * this parser is lenient, so a successful parse does not indicate that the
- * input string was valid JSON. All of the following syntax errors will be
- * ignored:
+ *
+ * For best interoperability and performance use JSON that complies with RFC 4627, such as
+ * that generated by {@link JSONStringer}. For legacy reasons this parser is lenient, so a
+ * successful parse does not indicate that the input string was valid JSON. All of the
+ * following syntax errors will be ignored:
* Each tokener may be used to parse a single JSON string. Instances of this
- * class are not thread safe. Although this class is nonfinal, it was not
- * designed for inheritance and should not be subclassed. In particular,
- * self-use by overrideable methods is not specified. See Effective Java
- * Item 17, "Design and Document or inheritance or else prohibit it" for further
- * information.
+ *
+ * Each tokener may be used to parse a single JSON string. Instances of this class are not
+ * thread safe. Although this class is nonfinal, it was not designed for inheritance and
+ * should not be subclassed. In particular, self-use by overrideable methods is not
+ * specified. See Effective Java Item 17,
+ * "Design and Document or inheritance or else prohibit it" for further information.
*/
public class JSONTokener {
- /** The input JSON. */
+ /**
+ * The input JSON.
+ */
private final String in;
/**
- * The index of the next character to be returned by {@link #next}. When
- * the input is exhausted, this equals the input's length.
+ * The index of the next character to be returned by {@link #next}. When the input is
+ * exhausted, this equals the input's length.
*/
private int pos;
/**
- * @param in JSON encoded string. Null is not permitted and will yield a
- * tokener that throws {@code NullPointerExceptions} when methods are
- * called.
+ * @param in JSON encoded string. Null is not permitted and will yield a tokener that
+ * throws {@code NullPointerExceptions} when methods are called.
*/
public JSONTokener(String in) {
// consume an optional byte order mark (BOM) if it exists
@@ -85,30 +84,29 @@ public JSONTokener(String in) {
/**
* Returns the next value from the input.
- *
- * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean,
- * Integer, Long, Double or {@link JSONObject#NULL}.
+ * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long,
+ * Double or {@link JSONObject#NULL}.
* @throws JSONException if the input is malformed.
*/
public Object nextValue() throws JSONException {
int c = nextCleanInternal();
switch (c) {
- case -1:
- throw syntaxError("End of input");
+ case -1:
+ throw syntaxError("End of input");
- case '{':
- return readObject();
+ case '{':
+ return readObject();
- case '[':
- return readArray();
+ case '[':
+ return readArray();
- case '\'':
- case '"':
- return nextString((char) c);
+ case '\'':
+ case '"':
+ return nextString((char) c);
- default:
- this.pos--;
- return readLiteral();
+ default:
+ this.pos--;
+ return readLiteral();
}
}
@@ -116,50 +114,50 @@ private int nextCleanInternal() throws JSONException {
while (this.pos < this.in.length()) {
int c = this.in.charAt(this.pos++);
switch (c) {
- case '\t':
- case ' ':
- case '\n':
- case '\r':
- continue;
+ case '\t':
+ case ' ':
+ case '\n':
+ case '\r':
+ continue;
- case '/':
- if (this.pos == this.in.length()) {
- return c;
- }
+ case '/':
+ if (this.pos == this.in.length()) {
+ return c;
+ }
- char peek = this.in.charAt(this.pos);
- switch (peek) {
- case '*':
- // skip a /* c-style comment */
- this.pos++;
- int commentEnd = this.in.indexOf("*/", this.pos);
- if (commentEnd == -1) {
- throw syntaxError("Unterminated comment");
- }
- this.pos = commentEnd + 2;
- continue;
-
- case '/':
- // skip a // end-of-line comment
- this.pos++;
- skipToEndOfLine();
- continue;
-
- default:
- return c;
+ char peek = this.in.charAt(this.pos);
+ switch (peek) {
+ case '*':
+ // skip a /* c-style comment */
+ this.pos++;
+ int commentEnd = this.in.indexOf("*/", this.pos);
+ if (commentEnd == -1) {
+ throw syntaxError("Unterminated comment");
}
+ this.pos = commentEnd + 2;
+ continue;
- case '#':
- /*
- * Skip a # hash end-of-line comment. The JSON RFC doesn't
- * specify this behavior, but it's required to parse
- * existing documents. See http://b/2571423.
- */
+ case '/':
+ // skip a // end-of-line comment
+ this.pos++;
skipToEndOfLine();
continue;
default:
return c;
+ }
+
+ case '#':
+ /*
+ * Skip a # hash end-of-line comment. The JSON RFC doesn't specify this
+ * behavior, but it's required to parse existing documents. See
+ * http://b/2571423.
+ */
+ skipToEndOfLine();
+ continue;
+
+ default:
+ return c;
}
}
@@ -167,9 +165,8 @@ private int nextCleanInternal() throws JSONException {
}
/**
- * Advances the position until after the next newline character. If the line
- * is terminated by "\r\n", the '\n' must be consumed as whitespace by the
- * caller.
+ * Advances the position until after the next newline character. If the line is
+ * terminated by "\r\n", the '\n' must be consumed as whitespace by the caller.
*/
private void skipToEndOfLine() {
for (; this.pos < this.in.length(); this.pos++) {
@@ -182,22 +179,20 @@ private void skipToEndOfLine() {
}
/**
- * Returns the string up to but not including {@code quote}, unescaping any
- * character escape sequences encountered along the way. The opening quote
- * should have already been read. This consumes the closing quote, but does
- * not include it in the returned string.
- *
+ * Returns the string up to but not including {@code quote}, unescaping any character
+ * escape sequences encountered along the way. The opening quote should have already
+ * been read. This consumes the closing quote, but does not include it in the returned
+ * string.
* @param quote either ' or ".
* @return the string up to but not including {@code quote}
- * @throws NumberFormatException if any unicode escape sequences are
- * malformed.
+ * @throws NumberFormatException if any unicode escape sequences are malformed.
* @throws JSONException if processing of json failed
*/
public String nextString(char quote) throws JSONException {
/*
- * For strings that are free of escape sequences, we can just extract
- * the result as a substring of the input. But if we encounter an escape
- * sequence, we need to use a StringBuilder to compose the result.
+ * For strings that are free of escape sequences, we can just extract the result
+ * as a substring of the input. But if we encounter an escape sequence, we need to
+ * use a StringBuilder to compose the result.
*/
StringBuilder builder = null;
@@ -234,54 +229,50 @@ public String nextString(char quote) throws JSONException {
}
/**
- * Unescapes the character identified by the character or characters that
- * immediately follow a backslash. The backslash '\' should have already
- * been read. This supports both unicode escapes "u000A" and two-character
- * escapes "\n".
- *
+ * Unescapes the character identified by the character or characters that immediately
+ * follow a backslash. The backslash '\' should have already been read. This supports
+ * both unicode escapes "u000A" and two-character escapes "\n".
* @return the unescaped char
- * @throws NumberFormatException if any unicode escape sequences are
- * malformed.
+ * @throws NumberFormatException if any unicode escape sequences are malformed.
* @throws JSONException if processing of json failed
*/
private char readEscapeCharacter() throws JSONException {
char escaped = this.in.charAt(this.pos++);
switch (escaped) {
- case 'u':
- if (this.pos + 4 > this.in.length()) {
- throw syntaxError("Unterminated escape sequence");
- }
- String hex = this.in.substring(this.pos, this.pos + 4);
- this.pos += 4;
- return (char) Integer.parseInt(hex, 16);
+ case 'u':
+ if (this.pos + 4 > this.in.length()) {
+ throw syntaxError("Unterminated escape sequence");
+ }
+ String hex = this.in.substring(this.pos, this.pos + 4);
+ this.pos += 4;
+ return (char) Integer.parseInt(hex, 16);
- case 't':
- return '\t';
+ case 't':
+ return '\t';
- case 'b':
- return '\b';
+ case 'b':
+ return '\b';
- case 'n':
- return '\n';
+ case 'n':
+ return '\n';
- case 'r':
- return '\r';
+ case 'r':
+ return '\r';
- case 'f':
- return '\f';
+ case 'f':
+ return '\f';
- case '\'':
- case '"':
- case '\\':
- default:
- return escaped;
+ case '\'':
+ case '"':
+ case '\\':
+ default:
+ return escaped;
}
}
/**
- * Reads a null, boolean, numeric or unquoted string literal value. Numeric
- * values will be returned as an Integer, Long, or Double, in that order of
- * preference.
+ * Reads a null, boolean, numeric or unquoted string literal value. Numeric values
+ * will be returned as an Integer, Long, or Double, in that order of preference.
* @return a literal value
* @throws JSONException if processing of json failed
*/
@@ -324,9 +315,9 @@ else if (number.startsWith("0") && number.length() > 1) {
}
catch (NumberFormatException e) {
/*
- * This only happens for integral numbers greater than
- * Long.MAX_VALUE, numbers in exponential form (5e-10) and
- * unquoted strings. Fall through to try floating point.
+ * This only happens for integral numbers greater than Long.MAX_VALUE,
+ * numbers in exponential form (5e-10) and unquoted strings. Fall through
+ * to try floating point.
*/
}
}
@@ -343,10 +334,10 @@ else if (number.startsWith("0") && number.length() > 1) {
}
/**
- * Returns the string up to but not including any of the given characters or
- * a newline character. This does not consume the excluded character.
- * @return the string up to but not including any of the given characters or
- * a newline character
+ * Returns the string up to but not including any of the given characters or a newline
+ * character. This does not consume the excluded character.
+ * @return the string up to but not including any of the given characters or a newline
+ * character
*/
private String nextToInternal(String excluded) {
int start = this.pos;
@@ -360,8 +351,8 @@ private String nextToInternal(String excluded) {
}
/**
- * Reads a sequence of key/value pairs and the trailing closing brace '}' of
- * an object. The opening brace '{' should have already been read.
+ * Reads a sequence of key/value pairs and the trailing closing brace '}' of an
+ * object. The opening brace '{' should have already been read.
* @return an object
* @throws JSONException if processing of json failed
*/
@@ -390,9 +381,9 @@ else if (first != -1) {
}
/*
- * Expect the name/value separator to be either a colon ':', an
- * equals sign '=', or an arrow "=>". The last two are bogus but we
- * include them because that's what the original implementation did.
+ * Expect the name/value separator to be either a colon ':', an equals sign
+ * '=', or an arrow "=>". The last two are bogus but we include them because
+ * that's what the original implementation did.
*/
int separator = nextCleanInternal();
if (separator != ':' && separator != '=') {
@@ -405,22 +396,21 @@ else if (first != -1) {
result.put((String) name, nextValue());
switch (nextCleanInternal()) {
- case '}':
- return result;
- case ';':
- case ',':
- continue;
- default:
- throw syntaxError("Unterminated object");
+ case '}':
+ return result;
+ case ';':
+ case ',':
+ continue;
+ default:
+ throw syntaxError("Unterminated object");
}
}
}
/**
- * Reads a sequence of values and the trailing closing brace ']' of an
- * array. The opening brace '[' should have already been read. Note that
- * "[]" yields an empty array, but "[,]" returns a two-element array
- * equivalent to "[null,null]".
+ * Reads a sequence of values and the trailing closing brace ']' of an array. The
+ * opening brace '[' should have already been read. Note that "[]" yields an empty
+ * array, but "[,]" returns a two-element array equivalent to "[null,null]".
* @return an array
* @throws JSONException if processing of json failed
*/
@@ -432,41 +422,41 @@ private JSONArray readArray() throws JSONException {
while (true) {
switch (nextCleanInternal()) {
- case -1:
- throw syntaxError("Unterminated array");
- case ']':
- if (hasTrailingSeparator) {
- result.put(null);
- }
- return result;
- case ',':
- case ';':
- /* A separator without a value first means "null". */
+ case -1:
+ throw syntaxError("Unterminated array");
+ case ']':
+ if (hasTrailingSeparator) {
result.put(null);
- hasTrailingSeparator = true;
- continue;
- default:
- this.pos--;
+ }
+ return result;
+ case ',':
+ case ';':
+ /* A separator without a value first means "null". */
+ result.put(null);
+ hasTrailingSeparator = true;
+ continue;
+ default:
+ this.pos--;
}
result.put(nextValue());
switch (nextCleanInternal()) {
- case ']':
- return result;
- case ',':
- case ';':
- hasTrailingSeparator = true;
- continue;
- default:
- throw syntaxError("Unterminated array");
+ case ']':
+ return result;
+ case ',':
+ case ';':
+ hasTrailingSeparator = true;
+ continue;
+ default:
+ throw syntaxError("Unterminated array");
}
}
}
/**
- * Returns an exception containing the given message plus the current
- * position and the entire input string.
+ * Returns an exception containing the given message plus the current position and the
+ * entire input string.
* @param message the message
* @return an exception
*/
@@ -487,9 +477,9 @@ public String toString() {
/*
* Legacy APIs.
*
- * None of the methods below are on the critical path of parsing JSON
- * documents. They exist only because they were exposed by the original
- * implementation and may be used by some clients.
+ * None of the methods below are on the critical path of parsing JSON documents. They
+ * exist only because they were exposed by the original implementation and may be used
+ * by some clients.
*/
public boolean more() {
@@ -569,4 +559,5 @@ else if (hex >= 'a' && hex <= 'f') {
return -1;
}
}
+
}
+ * Encodes this object as a human readable JSON string for debugging, such as:
* {
* "query": "Pizza",
* "locations": [
@@ -740,9 +720,7 @@ public String toString() {
* 90210
* ]
* }
- *
- * @param indentSpaces the number of spaces to indent for each level of
- * nesting.
+ * @param indentSpaces the number of spaces to indent for each level of nesting.
* @return a string representation of the object.
* @throws JSONException if an error occurs
*/
@@ -762,9 +740,8 @@ void writeTo(JSONStringer stringer) throws JSONException {
/**
* Encodes the number as a JSON string.
- *
* @param number a finite value. May not be {@link Double#isNaN() NaNs} or
- * {@link Double#isInfinite() infinities}.
+ * {@link Double#isInfinite() infinities}.
* @return the encoded value
* @throws JSONException if an error occurs
*/
@@ -782,7 +759,7 @@ public static String numberToString(Number number) throws JSONException {
}
long longValue = number.longValue();
- if (doubleValue == (double) longValue) {
+ if (doubleValue == longValue) {
return Long.toString(longValue);
}
@@ -790,11 +767,9 @@ public static String numberToString(Number number) throws JSONException {
}
/**
- * Encodes {@code data} as a JSON string. This applies quotes and any
- * necessary character escaping.
- *
- * @param data the string to encode. Null will be interpreted as an empty
- * string.
+ * Encodes {@code data} as a JSON string. This applies quotes and any necessary
+ * character escaping.
+ * @param data the string to encode. Null will be interpreted as an empty string.
* @return the quoted value
*/
public static String quote(String data) {
@@ -815,18 +790,19 @@ public static String quote(String data) {
/**
* Wraps the given object if necessary.
- *
- *
+ * Implements {@link JSONObject#toString} and {@link JSONArray#toString}. Most application
+ * developers should use those methods directly and disregard this API. For example:
* JSONObject object = ...
* String json = object.toString();
- *
- *
- *
* Calls that would result in a malformed JSON string will fail with a
* {@link JSONException}.
- *
- *
+ * Parses a JSON (RFC 4627) encoded
+ * string into the corresponding object. Most clients of this class will use only need the
+ * {@link #JSONTokener(String) constructor} and {@link #nextValue} method. Example usage:
+ *
* String json = "{"
* + " \"query\": \"Pizza\", "
* + " \"locations\": [ 94043, 90210 ] "
@@ -31,49 +31,48 @@
* JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
* String query = object.getString("query");
* JSONArray locations = object.getJSONArray("locations");
- *
- *
- *
- *
- *