GH-1156 Remove org.json:json dependency

Use the already present Jackson ObjectMapper  instead to provide the same behaviour, where a value is parsed to check if it is a valid json structure, ie an array or an object.

Resolves #1173
Resolves #1156
This commit is contained in:
Garus, Henning
2024-08-12 21:18:27 +02:00
committed by Oleg Zhurakousky
parent c8c7ce41cc
commit 2bfaabb570
3 changed files with 19 additions and 44 deletions

View File

@@ -24,13 +24,14 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
@@ -137,33 +138,33 @@ public abstract class JsonMapper {
&& !value.getClass().getPackage().getName().startsWith("reactor.util.function")) {
return true;
}
if (value instanceof byte[]) {
value = new String((byte[]) value, StandardCharsets.UTF_8);
if (value instanceof byte[] byteValue) {
value = new String(byteValue, StandardCharsets.UTF_8);
}
if (value instanceof String) {
if (value instanceof String stringValue) {
try {
new JSONArray((String) value);
JsonNode node = mapper.readTree(stringValue);
return node instanceof ArrayNode;
}
catch (JSONException e) {
catch (JsonProcessingException e) {
return false;
}
return true;
}
return false;
}
public static boolean isJsonStringRepresentsMap(Object value) {
if (value instanceof byte[]) {
value = new String((byte[]) value, StandardCharsets.UTF_8);
if (value instanceof byte[] byteValue) {
value = new String(byteValue, StandardCharsets.UTF_8);
}
if (value instanceof String) {
if (value instanceof String stringValue) {
try {
new JSONObject(value);
JsonNode node = mapper.readTree(stringValue);
return node instanceof ObjectNode;
}
catch (JSONException e) {
catch (JsonProcessingException e) {
return false;
}
return true;
}
return false;
}