Skip to content

Commit d49b022

Browse files
committed
Shade json in configuration processor
This commit shades the json API in the configuration processor so that it doesn't bring `android-json` to the classpath anymore. Closes gh-10307
1 parent 1f14b11 commit d49b022

File tree

12 files changed

+2612
-20
lines changed

12 files changed

+2612
-20
lines changed

spring-boot-parent/src/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
<suppress files="Ansi.*\.java" checks="JavadocStyle" />
2323
<suppress files="LogLevel\.java" checks="JavadocVariable" />
2424
<suppress files="HelpMojo\.java" checks=".*"/>
25+
<suppress files="[\\/]org.springframework.boot.configurationprocessor.json[\\/].*\.java$" checks=".*"/>
2526
</suppressions>

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@
1818
<main.basedir>${basedir}/../..</main.basedir>
1919
</properties>
2020
<dependencies>
21-
<!-- Compile (should stick to the bare minimum) -->
22-
<dependency>
23-
<groupId>com.vaadin.external.google</groupId>
24-
<artifactId>android-json</artifactId>
25-
</dependency>
26-
<!-- Test -->
21+
<!-- Test -->
2722
<dependency>
2823
<groupId>org.projectlombok</groupId>
2924
<artifactId>lombok</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (C) 2010 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.configurationprocessor.json;
18+
19+
class JSON {
20+
/**
21+
* Returns the input if it is a JSON-permissible value; throws otherwise.
22+
*/
23+
static double checkDouble(double d) throws JSONException {
24+
if (Double.isInfinite(d) || Double.isNaN(d)) {
25+
throw new JSONException("Forbidden numeric value: " + d);
26+
}
27+
return d;
28+
}
29+
30+
static Boolean toBoolean(Object value) {
31+
if (value instanceof Boolean) {
32+
return (Boolean) value;
33+
} else if (value instanceof String) {
34+
String stringValue = (String) value;
35+
if ("true".equalsIgnoreCase(stringValue)) {
36+
return true;
37+
} else if ("false".equalsIgnoreCase(stringValue)) {
38+
return false;
39+
}
40+
}
41+
return null;
42+
}
43+
44+
static Double toDouble(Object value) {
45+
if (value instanceof Double) {
46+
return (Double) value;
47+
} else if (value instanceof Number) {
48+
return ((Number) value).doubleValue();
49+
} else if (value instanceof String) {
50+
try {
51+
return Double.valueOf((String) value);
52+
} catch (NumberFormatException ignored) {
53+
}
54+
}
55+
return null;
56+
}
57+
58+
static Integer toInteger(Object value) {
59+
if (value instanceof Integer) {
60+
return (Integer) value;
61+
} else if (value instanceof Number) {
62+
return ((Number) value).intValue();
63+
} else if (value instanceof String) {
64+
try {
65+
return (int) Double.parseDouble((String) value);
66+
} catch (NumberFormatException ignored) {
67+
}
68+
}
69+
return null;
70+
}
71+
72+
static Long toLong(Object value) {
73+
if (value instanceof Long) {
74+
return (Long) value;
75+
} else if (value instanceof Number) {
76+
return ((Number) value).longValue();
77+
} else if (value instanceof String) {
78+
try {
79+
return (long) Double.parseDouble((String) value);
80+
} catch (NumberFormatException ignored) {
81+
}
82+
}
83+
return null;
84+
}
85+
86+
static String toString(Object value) {
87+
if (value instanceof String) {
88+
return (String) value;
89+
} else if (value != null) {
90+
return String.valueOf(value);
91+
}
92+
return null;
93+
}
94+
95+
public static JSONException typeMismatch(Object indexOrName, Object actual,
96+
String requiredType) throws JSONException {
97+
if (actual == null) {
98+
throw new JSONException("Value at " + indexOrName + " is null.");
99+
} else {
100+
throw new JSONException("Value " + actual + " at " + indexOrName
101+
+ " of type " + actual.getClass().getName()
102+
+ " cannot be converted to " + requiredType);
103+
}
104+
}
105+
106+
public static JSONException typeMismatch(Object actual, String requiredType)
107+
throws JSONException {
108+
if (actual == null) {
109+
throw new JSONException("Value is null.");
110+
} else {
111+
throw new JSONException("Value " + actual
112+
+ " of type " + actual.getClass().getName()
113+
+ " cannot be converted to " + requiredType);
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)