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

Merge branch '1.5.x'

parents 41c02b30 700d3c39
......@@ -36,6 +36,24 @@
<proc>none</proc>
</configuration>
</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>
</build>
</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 @@
package org.springframework.boot.configurationprocessor.json;
class JSON {
/**
* Returns the input if it is a JSON-permissible value; throws otherwise.
*/
static double checkDouble(double d) throws JSONException {
if (Double.isInfinite(d) || Double.isNaN(d)) {
throw new JSONException("Forbidden numeric value: " + d);
......@@ -31,12 +29,12 @@ class JSON {
if (value instanceof Boolean) {
return (Boolean) value;
}
else if (value instanceof String) {
if (value instanceof String) {
String stringValue = (String) value;
if ("true".equalsIgnoreCase(stringValue)) {
return true;
}
else if ("false".equalsIgnoreCase(stringValue)) {
if ("false".equalsIgnoreCase(stringValue)) {
return false;
}
}
......@@ -47,10 +45,10 @@ class JSON {
if (value instanceof Double) {
return (Double) value;
}
else if (value instanceof Number) {
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
else if (value instanceof String) {
if (value instanceof String) {
try {
return Double.valueOf((String) value);
}
......@@ -64,10 +62,10 @@ class JSON {
if (value instanceof Integer) {
return (Integer) value;
}
else if (value instanceof Number) {
if (value instanceof Number) {
return ((Number) value).intValue();
}
else if (value instanceof String) {
if (value instanceof String) {
try {
return (int) Double.parseDouble((String) value);
}
......@@ -81,10 +79,10 @@ class JSON {
if (value instanceof Long) {
return (Long) value;
}
else if (value instanceof Number) {
if (value instanceof Number) {
return ((Number) value).longValue();
}
else if (value instanceof String) {
if (value instanceof String) {
try {
return (long) Double.parseDouble((String) value);
}
......@@ -98,7 +96,7 @@ class JSON {
if (value instanceof String) {
return (String) value;
}
else if (value != null) {
if (value != null) {
return String.valueOf(value);
}
return null;
......@@ -109,11 +107,9 @@ class JSON {
if (actual == null) {
throw new JSONException("Value at " + indexOrName + " is null.");
}
else {
throw new JSONException("Value " + actual + " at " + indexOrName
+ " of type " + actual.getClass().getName()
+ " cannot be converted to " + requiredType);
}
throw new JSONException("Value " + actual + " at " + indexOrName + " of type "
+ actual.getClass().getName() + " cannot be converted to "
+ requiredType);
}
public static JSONException typeMismatch(Object actual, String requiredType)
......@@ -121,10 +117,9 @@ class JSON {
if (actual == null) {
throw new JSONException("Value is null.");
}
else {
throw new JSONException("Value " + actual
+ " of type " + actual.getClass().getName()
throw new JSONException(
"Value " + actual + " of type " + actual.getClass().getName()
+ " 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");
* you may not use this file except in compliance with the License.
......@@ -16,23 +16,22 @@
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:
* <ul>
* <li>Attempts to parse or construct malformed documents
* <li>Use of null as a name
* <li>Use of numeric types not available to JSON, such as {@link
* Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}.
* <li>Use of numeric types not available to JSON, such as {@link Double#isNaN() NaNs} or
* {@link Double#isInfinite() infinities}.
* <li>Lookups using an out of range index or nonexistent name
* <li>Type mismatches on lookups
* </ul>
*
* <p>Although this is a checked exception, it is rarely recoverable. Most
* callers should simply wrap this exception in an unchecked exception and
* rethrow:
* <pre> public JSONArray toJSONObject() {
* <p>
* Although this is a checked exception, it is rarely recoverable. Most callers should
* simply wrap this exception in an unchecked exception and rethrow: <pre class="code">
* public JSONArray toJSONObject() {
* try {
* JSONObject result = new JSONObject();
* ...
......@@ -46,4 +45,5 @@ public class JSONException extends Exception {
public JSONException(String 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