Commit 87bccb96 authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.5.x'

parents 41c02b30 700d3c39
...@@ -36,6 +36,24 @@ ...@@ -36,6 +36,24 @@
<proc>none</proc> <proc>none</proc>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-json-shade-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/json-shade/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
## Shaded JSON
This source was originally taken from `com.vaadin.external.google:android-json` which
provides a clean room re-implementation of the `org.json` APIs and does not include the
"Do not use for evil" clause.
...@@ -17,9 +17,7 @@ ...@@ -17,9 +17,7 @@
package org.springframework.boot.configurationprocessor.json; package org.springframework.boot.configurationprocessor.json;
class JSON { class JSON {
/**
* Returns the input if it is a JSON-permissible value; throws otherwise.
*/
static double checkDouble(double d) throws JSONException { static double checkDouble(double d) throws JSONException {
if (Double.isInfinite(d) || Double.isNaN(d)) { if (Double.isInfinite(d) || Double.isNaN(d)) {
throw new JSONException("Forbidden numeric value: " + d); throw new JSONException("Forbidden numeric value: " + d);
...@@ -31,12 +29,12 @@ class JSON { ...@@ -31,12 +29,12 @@ class JSON {
if (value instanceof Boolean) { if (value instanceof Boolean) {
return (Boolean) value; return (Boolean) value;
} }
else if (value instanceof String) { if (value instanceof String) {
String stringValue = (String) value; String stringValue = (String) value;
if ("true".equalsIgnoreCase(stringValue)) { if ("true".equalsIgnoreCase(stringValue)) {
return true; return true;
} }
else if ("false".equalsIgnoreCase(stringValue)) { if ("false".equalsIgnoreCase(stringValue)) {
return false; return false;
} }
} }
...@@ -47,10 +45,10 @@ class JSON { ...@@ -47,10 +45,10 @@ class JSON {
if (value instanceof Double) { if (value instanceof Double) {
return (Double) value; return (Double) value;
} }
else if (value instanceof Number) { if (value instanceof Number) {
return ((Number) value).doubleValue(); return ((Number) value).doubleValue();
} }
else if (value instanceof String) { if (value instanceof String) {
try { try {
return Double.valueOf((String) value); return Double.valueOf((String) value);
} }
...@@ -64,10 +62,10 @@ class JSON { ...@@ -64,10 +62,10 @@ class JSON {
if (value instanceof Integer) { if (value instanceof Integer) {
return (Integer) value; return (Integer) value;
} }
else if (value instanceof Number) { if (value instanceof Number) {
return ((Number) value).intValue(); return ((Number) value).intValue();
} }
else if (value instanceof String) { if (value instanceof String) {
try { try {
return (int) Double.parseDouble((String) value); return (int) Double.parseDouble((String) value);
} }
...@@ -81,10 +79,10 @@ class JSON { ...@@ -81,10 +79,10 @@ class JSON {
if (value instanceof Long) { if (value instanceof Long) {
return (Long) value; return (Long) value;
} }
else if (value instanceof Number) { if (value instanceof Number) {
return ((Number) value).longValue(); return ((Number) value).longValue();
} }
else if (value instanceof String) { if (value instanceof String) {
try { try {
return (long) Double.parseDouble((String) value); return (long) Double.parseDouble((String) value);
} }
...@@ -98,7 +96,7 @@ class JSON { ...@@ -98,7 +96,7 @@ class JSON {
if (value instanceof String) { if (value instanceof String) {
return (String) value; return (String) value;
} }
else if (value != null) { if (value != null) {
return String.valueOf(value); return String.valueOf(value);
} }
return null; return null;
...@@ -109,11 +107,9 @@ class JSON { ...@@ -109,11 +107,9 @@ class JSON {
if (actual == null) { if (actual == null) {
throw new JSONException("Value at " + indexOrName + " is null."); throw new JSONException("Value at " + indexOrName + " is null.");
} }
else { throw new JSONException("Value " + actual + " at " + indexOrName + " of type "
throw new JSONException("Value " + actual + " at " + indexOrName + actual.getClass().getName() + " cannot be converted to "
+ " of type " + actual.getClass().getName() + requiredType);
+ " cannot be converted to " + requiredType);
}
} }
public static JSONException typeMismatch(Object actual, String requiredType) public static JSONException typeMismatch(Object actual, String requiredType)
...@@ -121,10 +117,9 @@ class JSON { ...@@ -121,10 +117,9 @@ class JSON {
if (actual == null) { if (actual == null) {
throw new JSONException("Value is null."); throw new JSONException("Value is null.");
} }
else { throw new JSONException(
throw new JSONException("Value " + actual "Value " + actual + " of type " + actual.getClass().getName()
+ " of type " + actual.getClass().getName() + " cannot be converted to " + requiredType);
+ " cannot be converted to " + requiredType);
}
} }
} }
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright (C) 2010 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,23 +16,22 @@ ...@@ -16,23 +16,22 @@
package org.springframework.boot.configurationprocessor.json; package org.springframework.boot.configurationprocessor.json;
// Note: this class was written without inspecting the non-free org.json source code. // Note: this class was written without inspecting the non-free org.json sourcecode.
/** /**
* Thrown to indicate a problem with the JSON API. Such problems include: * Thrown to indicate a problem with the JSON API. Such problems include:
* <ul> * <ul>
* <li>Attempts to parse or construct malformed documents * <li>Attempts to parse or construct malformed documents
* <li>Use of null as a name * <li>Use of null as a name
* <li>Use of numeric types not available to JSON, such as {@link * <li>Use of numeric types not available to JSON, such as {@link Double#isNaN() NaNs} or
* Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}. * {@link Double#isInfinite() infinities}.
* <li>Lookups using an out of range index or nonexistent name * <li>Lookups using an out of range index or nonexistent name
* <li>Type mismatches on lookups * <li>Type mismatches on lookups
* </ul> * </ul>
* * <p>
* <p>Although this is a checked exception, it is rarely recoverable. Most * Although this is a checked exception, it is rarely recoverable. Most callers should
* callers should simply wrap this exception in an unchecked exception and * simply wrap this exception in an unchecked exception and rethrow: <pre class="code">
* rethrow: * public JSONArray toJSONObject() {
* <pre> public JSONArray toJSONObject() {
* try { * try {
* JSONObject result = new JSONObject(); * JSONObject result = new JSONObject();
* ... * ...
...@@ -46,4 +45,5 @@ public class JSONException extends Exception { ...@@ -46,4 +45,5 @@ public class JSONException extends Exception {
public JSONException(String s) { public JSONException(String s) {
super(s); super(s);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment