Resolve itest runbundles for Gson and Commons Lang upgrades and fix JsonParser deprecations (#10345)

* Resolve itest runbundles for Gson and Commons Lang upgrades
* Fix JsonParser deprecations too
* Fix feature verification

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2021-03-18 12:15:15 +01:00
committed by GitHub
parent 009208adee
commit 580f293766
86 changed files with 206 additions and 215 deletions

View File

@@ -98,10 +98,9 @@ public final class Utils {
public static JsonObject convertFileToJSON(URL fileName) throws JsonIOException, JsonSyntaxException,
JsonParseException, IOException, URISyntaxException, NoSuchFileException {
JsonObject jsonObject = new JsonObject();
JsonParser parser = new JsonParser();
try (InputStream inputStream = fileName.openStream();
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
JsonElement jsonElement = parser.parse(reader);
JsonElement jsonElement = JsonParser.parseReader(reader);
jsonObject = jsonElement.getAsJsonObject();
return jsonObject;
}

View File

@@ -74,7 +74,6 @@ public class MiCloudConnector {
private static final TimeZone TZ = TimeZone.getDefault();
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("OOOO");
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
private static final JsonParser PARSER = new JsonParser();
private final String clientId;
@@ -156,7 +155,7 @@ public class MiCloudConnector {
logger.trace("response: {}", mapResponse);
String errorMsg = "";
try {
JsonElement response = PARSER.parse(mapResponse);
JsonElement response = JsonParser.parseString(mapResponse);
if (response.isJsonObject()) {
logger.debug("Received JSON message {}", response);
if (response.getAsJsonObject().has("result")
@@ -210,7 +209,7 @@ public class MiCloudConnector {
final String response = getDeviceString(country);
List<CloudDeviceDTO> devicesList = new ArrayList<>();
try {
final JsonElement resp = PARSER.parse(response);
final JsonElement resp = JsonParser.parseString(response);
if (resp.isJsonObject()) {
final JsonObject jor = resp.getAsJsonObject();
if (jor.has("result")) {
@@ -413,7 +412,7 @@ public class MiCloudConnector {
logger.trace("Xiaomi Login step 1 content response= {}", content);
logger.trace("Xiaomi Login step 1 response = {}", responseStep1);
try {
JsonElement resp = new JsonParser().parse(parseJson(content));
JsonElement resp = JsonParser.parseString(parseJson(content));
if (resp.isJsonObject() && resp.getAsJsonObject().has("_sign")) {
String sign = resp.getAsJsonObject().get("_sign").getAsString();
logger.trace("Xiaomi Login step 1 sign = {}", sign);
@@ -457,7 +456,7 @@ public class MiCloudConnector {
logger.trace("Xiaomi login step 2 response = {}", responseStep2);
logger.trace("Xiaomi login step 2 content = {}", content2);
JsonElement resp2 = new JsonParser().parse(parseJson(content2));
JsonElement resp2 = JsonParser.parseString(parseJson(content2));
CloudLoginDTO jsonResp = GSON.fromJson(resp2, CloudLoginDTO.class);
if (jsonResp == null) {
throw new MiCloudException("Error getting logon details from step 2: " + content2);

View File

@@ -58,7 +58,6 @@ import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
* The {@link MiIoAbstractHandler} is responsible for handling commands, which are
@@ -76,7 +75,6 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
protected MiIoDevices miDevice = MiIoDevices.UNKNOWN;
protected boolean isIdentified;
protected final JsonParser parser = new JsonParser();
protected byte[] token = new byte[0];
protected @Nullable MiIoBindingConfiguration configuration;

View File

@@ -73,6 +73,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
@@ -505,7 +506,8 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
private void updatePropsFromJsonArray(MiIoSendCommand response) {
JsonArray res = response.getResult().getAsJsonArray();
JsonArray para = parser.parse(response.getCommandString()).getAsJsonObject().get("params").getAsJsonArray();
JsonArray para = JsonParser.parseString(response.getCommandString()).getAsJsonObject().get("params")
.getAsJsonArray();
if (res.size() != para.size()) {
logger.debug("Unexpected size different. Request size {}, response size {}. (Req: {}, Resp:{})",
para.size(), res.size(), para, res);

View File

@@ -73,7 +73,6 @@ public class MiIoAsyncCommunication {
private AtomicInteger id = new AtomicInteger(-1);
private int timeDelta;
private int timeStamp;
private final JsonParser parser;
private @Nullable MessageSenderThread senderThread;
private boolean connected;
private ThingStatusDetail status = ThingStatusDetail.NONE;
@@ -94,7 +93,6 @@ public class MiIoAsyncCommunication {
this.timeout = timeout;
this.cloudConnector = cloudConnector;
setId(id);
parser = new JsonParser();
startReceiver();
}
@@ -150,7 +148,7 @@ public class MiIoAsyncCommunication {
}
fullCommand.addProperty("id", cmdId);
fullCommand.addProperty("method", command);
fullCommand.add("params", parser.parse(params));
fullCommand.add("params", JsonParser.parseString(params));
MiIoSendCommand sendCmd = new MiIoSendCommand(cmdId, MiIoCommand.getCommand(command), fullCommand,
cloudServer);
concurrentLinkedQueue.add(sendCmd);
@@ -188,7 +186,7 @@ public class MiIoAsyncCommunication {
// hack due to avoid invalid json errors from some misbehaving device firmwares
decryptedResponse = decryptedResponse.replace(",,", ",");
JsonElement response;
response = parser.parse(decryptedResponse);
response = JsonParser.parseString(decryptedResponse);
if (!response.isJsonObject()) {
errorMsg = "Received message is not a JSON object ";
} else {

View File

@@ -292,8 +292,7 @@ public class ReadmeHelper {
JsonObject jsonObject = new JsonObject();
try {
JsonParser parser = new JsonParser();
JsonElement jsonElement = parser.parse(new FileReader(fileName));
JsonElement jsonElement = JsonParser.parseReader(new FileReader(fileName));
jsonObject = jsonElement.getAsJsonObject();
} catch (FileNotFoundException e) {
//