Skip to content

Commit

Permalink
Relocate shaded JSON API in annotation-processor
Browse files Browse the repository at this point in the history
Move the 'shade' copy of the JSON API to a separate src folder to make
it clearer that we don't own the code. Also polished some formatting
and suppressed a few warnings.

Closes gh-10307
  • Loading branch information
philwebb committed Jan 8, 2018
1 parent ad9cf39 commit 700d3c3
Show file tree
Hide file tree
Showing 8 changed files with 612 additions and 660 deletions.
18 changes: 18 additions & 0 deletions spring-boot-tools/spring-boot-configuration-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -31,12 +29,12 @@ static Boolean toBoolean(Object value) {
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;
}
}
Expand All @@ -47,10 +45,10 @@ static Double toDouble(Object value) {
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);
}
Expand All @@ -64,10 +62,10 @@ static Integer toInteger(Object value) {
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);
}
Expand All @@ -81,10 +79,10 @@ static Long toLong(Object value) {
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);
}
Expand All @@ -98,7 +96,7 @@ static String toString(Object value) {
if (value instanceof String) {
return (String) value;
}
else if (value != null) {
if (value != null) {
return String.valueOf(value);
}
return null;
Expand All @@ -109,22 +107,19 @@ public static JSONException typeMismatch(Object indexOrName, Object actual,
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)
throws JSONException {
if (actual == null) {
throw new JSONException("Value is null.");
}
else {
throw new JSONException("Value " + actual
+ " of type " + actual.getClass().getName()
+ " cannot be converted to " + requiredType);
}
throw new JSONException(
"Value " + actual + " of type " + actual.getClass().getName()
+ " cannot be converted to " + requiredType);
}

}
Loading

0 comments on commit 700d3c3

Please sign in to comment.