Skip to content

Commit 700d3c3

Browse files
committed
Relocate shaded JSON API in annotation-processor
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
1 parent ad9cf39 commit 700d3c3

File tree

8 files changed

+612
-660
lines changed

8 files changed

+612
-660
lines changed

spring-boot-tools/spring-boot-configuration-processor/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@
4040
<proc>none</proc>
4141
</configuration>
4242
</plugin>
43+
<plugin>
44+
<groupId>org.codehaus.mojo</groupId>
45+
<artifactId>build-helper-maven-plugin</artifactId>
46+
<executions>
47+
<execution>
48+
<id>add-json-shade-source</id>
49+
<phase>generate-sources</phase>
50+
<goals>
51+
<goal>add-source</goal>
52+
</goals>
53+
<configuration>
54+
<sources>
55+
<source>${basedir}/src/json-shade/java</source>
56+
</sources>
57+
</configuration>
58+
</execution>
59+
</executions>
60+
</plugin>
4361
</plugins>
4462
</build>
4563
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Shaded JSON
2+
3+
This source was originally taken from `com.vaadin.external.google:android-json` which
4+
provides a clean room re-implementation of the `org.json` APIs and does not include the
5+
"Do not use for evil" clause.
Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package org.springframework.boot.configurationprocessor.json;
1818

1919
class JSON {
20-
/**
21-
* Returns the input if it is a JSON-permissible value; throws otherwise.
22-
*/
20+
2321
static double checkDouble(double d) throws JSONException {
2422
if (Double.isInfinite(d) || Double.isNaN(d)) {
2523
throw new JSONException("Forbidden numeric value: " + d);
@@ -31,12 +29,12 @@ static Boolean toBoolean(Object value) {
3129
if (value instanceof Boolean) {
3230
return (Boolean) value;
3331
}
34-
else if (value instanceof String) {
32+
if (value instanceof String) {
3533
String stringValue = (String) value;
3634
if ("true".equalsIgnoreCase(stringValue)) {
3735
return true;
3836
}
39-
else if ("false".equalsIgnoreCase(stringValue)) {
37+
if ("false".equalsIgnoreCase(stringValue)) {
4038
return false;
4139
}
4240
}
@@ -47,10 +45,10 @@ static Double toDouble(Object value) {
4745
if (value instanceof Double) {
4846
return (Double) value;
4947
}
50-
else if (value instanceof Number) {
48+
if (value instanceof Number) {
5149
return ((Number) value).doubleValue();
5250
}
53-
else if (value instanceof String) {
51+
if (value instanceof String) {
5452
try {
5553
return Double.valueOf((String) value);
5654
}
@@ -64,10 +62,10 @@ static Integer toInteger(Object value) {
6462
if (value instanceof Integer) {
6563
return (Integer) value;
6664
}
67-
else if (value instanceof Number) {
65+
if (value instanceof Number) {
6866
return ((Number) value).intValue();
6967
}
70-
else if (value instanceof String) {
68+
if (value instanceof String) {
7169
try {
7270
return (int) Double.parseDouble((String) value);
7371
}
@@ -81,10 +79,10 @@ static Long toLong(Object value) {
8179
if (value instanceof Long) {
8280
return (Long) value;
8381
}
84-
else if (value instanceof Number) {
82+
if (value instanceof Number) {
8583
return ((Number) value).longValue();
8684
}
87-
else if (value instanceof String) {
85+
if (value instanceof String) {
8886
try {
8987
return (long) Double.parseDouble((String) value);
9088
}
@@ -98,7 +96,7 @@ static String toString(Object value) {
9896
if (value instanceof String) {
9997
return (String) value;
10098
}
101-
else if (value != null) {
99+
if (value != null) {
102100
return String.valueOf(value);
103101
}
104102
return null;
@@ -109,22 +107,19 @@ public static JSONException typeMismatch(Object indexOrName, Object actual,
109107
if (actual == null) {
110108
throw new JSONException("Value at " + indexOrName + " is null.");
111109
}
112-
else {
113-
throw new JSONException("Value " + actual + " at " + indexOrName
114-
+ " of type " + actual.getClass().getName()
115-
+ " cannot be converted to " + requiredType);
116-
}
110+
throw new JSONException("Value " + actual + " at " + indexOrName + " of type "
111+
+ actual.getClass().getName() + " cannot be converted to "
112+
+ requiredType);
117113
}
118114

119115
public static JSONException typeMismatch(Object actual, String requiredType)
120116
throws JSONException {
121117
if (actual == null) {
122118
throw new JSONException("Value is null.");
123119
}
124-
else {
125-
throw new JSONException("Value " + actual
126-
+ " of type " + actual.getClass().getName()
127-
+ " cannot be converted to " + requiredType);
128-
}
120+
throw new JSONException(
121+
"Value " + actual + " of type " + actual.getClass().getName()
122+
+ " cannot be converted to " + requiredType);
129123
}
124+
130125
}

0 commit comments

Comments
 (0)