Drop support for org.json:json-based JSON parsing

Closes gh-8710
This commit is contained in:
Andy Wilkinson 2017-05-04 10:23:26 +01:00
parent 05cf41bd9e
commit 11c3c4c20b
6 changed files with 1 additions and 137 deletions

View File

@ -117,7 +117,6 @@
<joda-time.version>2.9.9</joda-time.version>
<jolokia.version>1.3.6</jolokia.version>
<jooq.version>3.9.1</jooq.version>
<json.version>20140107</json.version>
<jsonassert.version>1.5.0</jsonassert.version>
<json-path.version>2.2.0</json-path.version>
<jstl.version>1.2</jstl.version>
@ -1787,11 +1786,6 @@
<artifactId>jolokia-core</artifactId>
<version>${jolokia.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>

View File

@ -463,11 +463,6 @@
<artifactId>infinispan-spring4-embedded</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>

View File

@ -174,11 +174,6 @@
<artifactId>hibernate-validator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>

View File

@ -1,85 +0,0 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.json;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Thin wrapper to adapt {@code org.json.JSONObject} to a {@link JsonParser}.
*
* @author Dave Syer
* @since 1.2.0
* @see JsonParserFactory
*/
public class JsonJsonParser implements JsonParser {
@Override
public Map<String, Object> parseMap(String json) {
Map<String, Object> map = new LinkedHashMap<>();
putAll(map, new JSONObject(json));
return map;
}
private void putAll(Map<String, Object> map, JSONObject object) {
for (Object key : object.keySet()) {
String name = key.toString();
Object value = object.get(name);
if (value instanceof JSONObject) {
Map<String, Object> nested = new LinkedHashMap<>();
putAll(nested, (JSONObject) value);
value = nested;
}
if (value instanceof JSONArray) {
List<Object> nested = new ArrayList<>();
addAll(nested, (JSONArray) value);
value = nested;
}
map.put(name, value);
}
}
private void addAll(List<Object> list, JSONArray array) {
for (int i = 0; i < array.length(); i++) {
Object value = array.get(i);
if (value instanceof JSONObject) {
Map<String, Object> nested = new LinkedHashMap<>();
putAll(nested, (JSONObject) value);
value = nested;
}
if (value instanceof JSONArray) {
List<Object> nested = new ArrayList<>();
addAll(nested, (JSONArray) value);
value = nested;
}
list.add(value);
}
}
@Override
public List<Object> parseList(String json) {
List<Object> nested = new ArrayList<>();
addAll(nested, new JSONArray(json));
return nested;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,7 +26,6 @@ import org.springframework.util.ClassUtils;
* @see GsonJsonParser
* @see YamlJsonParser
* @see JsonSimpleJsonParser
* @see JsonJsonParser
* @see BasicJsonParser
*/
public abstract class JsonParserFactory {
@ -50,9 +49,6 @@ public abstract class JsonParserFactory {
if (ClassUtils.isPresent("org.json.simple.JSONObject", null)) {
return new JsonSimpleJsonParser();
}
if (ClassUtils.isPresent("org.json.JSONObject", null)) {
return new JsonJsonParser();
}
return new BasicJsonParser();
}

View File

@ -1,31 +0,0 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.json;
/**
* Tests for {@link JsonJsonParser}.
*
* @author Dave Syer
*/
public class JsonJsonParserTests extends AbstractJsonParserTests {
@Override
protected JsonParser getParser() {
return new JsonJsonParser();
}
}