Skip to content

Commit

Permalink
Resolve itest runbundles for Gson and Commons Lang upgrades and fix J…
Browse files Browse the repository at this point in the history
…sonParser deprecations (openhab#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>
  • Loading branch information
wborn authored Mar 18, 2021
1 parent a3525aa commit fcc6be3
Show file tree
Hide file tree
Showing 86 changed files with 206 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public void serializeBsbLanApiParameterSetRequest() {
String serializedRequest = BsbLanApiContentConverter.toJson(request);

// verify serialized content
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(serializedRequest).getAsJsonObject();
JsonObject json = JsonParser.parseString(serializedRequest).getAsJsonObject();

// Although specifying the parameter as int (which would be nicer) also seems to work,
// we use a String here as this is the way it is noted in the documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public class SmartherApiConnector {

private final Logger logger = LoggerFactory.getLogger(SmartherApiConnector.class);

private final JsonParser parser = new JsonParser();
private final HttpClient httpClient;
private final ScheduledExecutorService scheduler;

Expand Down Expand Up @@ -305,7 +304,7 @@ private boolean processResponse(ContentResponse response) throws SmartherGateway
private String processErrorState(ContentResponse response)
throws SmartherTokenExpiredException, SmartherAuthorizationException, SmartherInvalidResponseException {
try {
final JsonElement element = parser.parse(response.getContentAsString());
final JsonElement element = JsonParser.parseString(response.getContentAsString());

if (element.isJsonObject()) {
final JsonObject object = element.getAsJsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static boolean checkResponse(JsonObject jsonResponse) {
public static JsonObject toJsonObject(String jsonResponse) {
if (jsonResponse != null && !jsonResponse.trim().equals("")) {
try {
return (JsonObject) new JsonParser().parse(jsonResponse);
return (JsonObject) JsonParser.parseString(jsonResponse);
} catch (JsonParseException e) {
LOGGER.error("An JsonParseException occurred by parsing jsonRequest: {}", jsonResponse, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public class EnturNoConnection {
private final EnturNoHandler handler;
private final HttpClient httpClient;

private final JsonParser parser = new JsonParser();
private final Gson gson = new Gson();

public EnturNoConnection(EnturNoHandler handler, HttpClient httpClient) {
Expand Down Expand Up @@ -168,7 +167,7 @@ private String getResponse(String url, Map<String, String> params) {
}

private String getErrorMessage(String response) {
JsonObject jsonResponse = parser.parse(response).getAsJsonObject();
JsonObject jsonResponse = JsonParser.parseString(response).getAsJsonObject();
if (jsonResponse.has(PROPERTY_MESSAGE)) {
return jsonResponse.get(PROPERTY_MESSAGE).getAsString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public class HeliosHandler221 extends BaseThingHandler {
private String ipAddress;

// JSON variables
private JsonParser parser = new JsonParser();
private Gson gson = new Gson();

private ScheduledFuture<?> logJob;
Expand Down Expand Up @@ -203,7 +202,7 @@ public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
return;
}

JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("initialize() Request : {}", systemTarget.resolveTemplate("ip", ipAddress)
Expand Down Expand Up @@ -303,7 +302,7 @@ private long subscribe() {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("subscribe() Request : {}",
Expand Down Expand Up @@ -365,7 +364,7 @@ private void unsubscribe() {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("unsubscribe() Request : {}",
Expand Down Expand Up @@ -426,7 +425,7 @@ private List<RESTEvent> pullLog(long logSubscriptionID) {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("pullLog() Request : {}",
Expand Down Expand Up @@ -488,7 +487,7 @@ private List<RESTSwitch> getSwitches() {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("getSwitches() Request : {}", switchTarget.resolveTemplate("ip", ipAddress)
Expand All @@ -506,7 +505,7 @@ private List<RESTSwitch> getSwitches() {
getThing().getUID().toString());
String result = jsonObject.get("result").toString();
result = result.replace("switch", "id");
JsonObject js = parser.parse(result).getAsJsonObject();
JsonObject js = JsonParser.parseString(result).getAsJsonObject();
RESTSwitch[] switchArray = gson.fromJson(js.getAsJsonArray("ides"), RESTSwitch[].class);
if (switchArray != null) {
return Arrays.asList(switchArray);
Expand Down Expand Up @@ -554,7 +553,7 @@ private void triggerSwitch(String id) {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("triggerSwitch() Request : {}",
Expand Down Expand Up @@ -609,7 +608,7 @@ private void enableSwitch(String id, boolean flag) {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("enableSwitch() Request : {}",
Expand Down Expand Up @@ -664,7 +663,7 @@ private List<RESTPort> getPorts() {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("getPorts() Request : {}", portTarget.resolveTemplate("ip", ipAddress)
Expand Down Expand Up @@ -732,7 +731,7 @@ private List<RESTPort> getPorts() {
}

if (response != null) {
JsonObject jsonObject = parser.parse(response.readEntity(String.class)).getAsJsonObject();
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();

if (logger.isTraceEnabled()) {
logger.trace("configureRunnable Request : {}", systemTarget.resolveTemplate("ip", ipAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ protected Result doNetwork(String address, String requestMethod, @Nullable Strin
return super.doNetwork(address, requestMethod, body);
} else {
String extractedAddress = Util.quickMatch("^http://[^/]+(.+)$", address);
JsonElement commandBody = new JsonParser().parse(body);
JsonElement commandBody = body == null ? null : JsonParser.parseString(body);
scheduleCommand = new ScheduleCommand(extractedAddress, requestMethod, commandBody);

// Return a fake result that will cause an exception and the callback to end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,8 @@ protected Bridge getBridge() {
}

private void assertJson(String expected, String actual) {
JsonParser parser = new JsonParser();
JsonElement jsonExpected = parser.parse(expected);
JsonElement jsonActual = parser.parse(actual);
JsonElement jsonExpected = JsonParser.parseString(expected);
JsonElement jsonActual = JsonParser.parseString(actual);
assertEquals(jsonExpected, jsonActual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Iammeter3080THandler(Thing thing) {
@SuppressWarnings("null")
@Override
protected void resolveData(String response) {
JsonElement iammeterDataElement = new JsonParser().parse(response);
JsonElement iammeterDataElement = JsonParser.parseString(response);
JsonObject iammeterData = iammeterDataElement.getAsJsonObject();
String keyWord = "Datas";
if (iammeterData.has("Datas") && iammeterData.has("SN")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IammeterHandler(Thing thing) {

@Override
protected void resolveData(String response) {
JsonElement iammeterDataElement = new JsonParser().parse(response);
JsonElement iammeterDataElement = JsonParser.parseString(response);
JsonObject iammeterData = iammeterDataElement.getAsJsonObject();
String keyWord = "Data";
if (iammeterData.has("data") || (iammeterData.has("Data") && iammeterData.has("SN"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public class KeContactHandler extends BaseThingHandler {

private final Logger logger = LoggerFactory.getLogger(KeContactHandler.class);

protected final JsonParser parser = new JsonParser();
private final KeContactTransceiver transceiver;

private ScheduledFuture<?> pollingJob;
Expand Down Expand Up @@ -236,7 +235,7 @@ protected void onData(ByteBuffer byteBuffer) {
}

try {
JsonObject readObject = parser.parse(response).getAsJsonObject();
JsonObject readObject = JsonParser.parseString(response).getAsJsonObject();

for (Entry<String, JsonElement> entry : readObject.entrySet()) {
switch (entry.getKey()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
public class KM200Device {

private final Logger logger = LoggerFactory.getLogger(KM200Device.class);
private final JsonParser jsonParser = new JsonParser();
private final KM200Cryption comCryption;
private final KM200Comm<KM200Device> deviceCommunicator;

Expand Down Expand Up @@ -360,7 +359,7 @@ public Boolean containsService(String service) {
logger.debug("{}: SERVICE NOT AVAILABLE", service);
return null;
} else {
nodeRoot = (JsonObject) jsonParser.parse(decodedData);
nodeRoot = (JsonObject) JsonParser.parseString(decodedData);
}
} else {
logger.debug("Get empty reply");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
@NonNullByDefault
public class KM200DataHandler {
private final Logger logger = LoggerFactory.getLogger(KM200DataHandler.class);
private final JsonParser jsonParser = new JsonParser();

private final KM200Device remoteDevice;

Expand Down Expand Up @@ -539,7 +538,7 @@ public KM200DataHandler(KM200Device remoteDevice) {
/* The JSONArray of switch items can be send directly */
try {
/* Check whether this input string is a valid JSONArray */
JsonArray userArray = (JsonArray) jsonParser.parse(val);
JsonArray userArray = (JsonArray) JsonParser.parseString(val);
newObject = userArray.getAsJsonObject();
} catch (JsonParseException e) {
logger.warn("The input for the switchProgram is not a valid JSONArray : {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class KodiClientSocket {

private boolean connected = false;

private final JsonParser parser = new JsonParser();
private final Gson mapper = new Gson();
private final URI uri;
private final WebSocketClient client;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void onConnect(Session wssession) {
@OnWebSocketMessage
public void onMessage(String message) {
logger.trace("Message received from server: {}", message);
final JsonObject json = parser.parse(message).getAsJsonObject();
final JsonObject json = JsonParser.parseString(message).getAsJsonObject();
if (json.has("id")) {
int messageId = json.get("id").getAsInt();
if (messageId == nextMessageId - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public static void executeConfigurationChanges(HttpClient httpClient, String url
String getAuthenticateResponse = httpClient.GET(urlLogin).getContentAsString();

try {
JsonObject getAuthenticateResponseJsonObject = (JsonObject) new JsonParser()
.parse(transformJsonResponse(getAuthenticateResponse));
JsonObject getAuthenticateResponseJsonObject = (JsonObject) JsonParser
.parseString(transformJsonResponse(getAuthenticateResponse));

sessionId = extractSessionId(getAuthenticateResponseJsonObject);

JsonObject authenticateJsonObject = new JsonParser().parse(getAuthenticateResponse.toString())
JsonObject authenticateJsonObject = JsonParser.parseString(getAuthenticateResponse.toString())
.getAsJsonObject();
salt = authenticateJsonObject.get("salt").getAsString();

Expand All @@ -84,8 +84,8 @@ public static void executeConfigurationChanges(HttpClient httpClient, String url
String loginPostResponse = new String(loginPostJsonDataContentResponse.getContent(),
StandardCharsets.UTF_8);

JsonObject loginPostJsonObject = (JsonObject) new JsonParser()
.parse(transformJsonResponse(loginPostResponse));
JsonObject loginPostJsonObject = (JsonObject) JsonParser
.parseString(transformJsonResponse(loginPostResponse));

sessionId = extractSessionId(loginPostJsonObject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ public void launchApplication(
@ActionInput(name = "appId", label = "@text/actionLaunchApplicationInputAppIDLabel", description = "@text/actionLaunchApplicationInputAppIDDesc") String appId,
@ActionInput(name = "params", label = "@text/actionLaunchApplicationInputParamsLabel", description = "@text/actionLaunchApplicationInputParamsDesc") String params) {
try {
JsonParser parser = new JsonParser();
JsonObject payload = (JsonObject) parser.parse(params);
JsonObject payload = (JsonObject) JsonParser.parseString(params);

Optional<AppInfo> appInfo = getAppInfos().stream().filter(a -> a.getId().equals(appId)).findFirst();
if (appInfo.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void handleMessage(String msg) {
logger.trace("Received message: {}", msg);

try {
JsonObject message = (JsonObject) new JsonParser().parse(msg);
JsonObject message = (JsonObject) JsonParser.parseString(msg);

if (!message.has("CommuniqueType")) {
logger.debug("No CommuniqueType found in message: {}", msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {

@Override
public void onApplianceStateChanged(String UID, DeviceClassObject dco) {
String myUID = ((String) getThing().getProperties().get(PROTOCOL_PROPERTY_NAME))
String myUID = (getThing().getProperties().get(PROTOCOL_PROPERTY_NAME))
+ (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);
String modelID = StringUtils.right(dco.DeviceClass,
dco.DeviceClass.length() - new String("com.miele.xgw3000.gateway.hdm.deviceclasses.Miele").length());
Expand Down Expand Up @@ -177,7 +177,7 @@ public void onApplianceStateChanged(String UID, DeviceClassObject dco) {

@Override
public void onAppliancePropertyChanged(String UID, DeviceProperty dp) {
String myUID = ((String) getThing().getProperties().get(PROTOCOL_PROPERTY_NAME))
String myUID = (getThing().getProperties().get(PROTOCOL_PROPERTY_NAME))
+ (String) getThing().getConfiguration().getProperties().get(APPLIANCE_ID);

if (myUID.equals(UID)) {
Expand All @@ -186,8 +186,7 @@ public void onAppliancePropertyChanged(String UID, DeviceProperty dp) {
if (dp.Metadata == null) {
String metadata = metaDataCache.get(new StringBuilder().append(dp.Name).toString().trim());
if (metadata != null) {
JsonParser parser = new JsonParser();
JsonObject jsonMetaData = (JsonObject) parser.parse(metadata);
JsonObject jsonMetaData = (JsonObject) JsonParser.parseString(metadata);
dmd = gson.fromJson(jsonMetaData, DeviceMetaData.class);
// only keep the enum, if any - that's all we care for events we receive via multicast
// all other fields are nulled
Expand All @@ -199,8 +198,7 @@ public void onAppliancePropertyChanged(String UID, DeviceProperty dp) {
}
if (dp.Metadata != null) {
String metadata = StringUtils.replace(dp.Metadata.toString(), "enum", "MieleEnum");
JsonParser parser = new JsonParser();
JsonObject jsonMetaData = (JsonObject) parser.parse(metadata);
JsonObject jsonMetaData = (JsonObject) JsonParser.parseString(metadata);
dmd = gson.fromJson(jsonMetaData, DeviceMetaData.class);
metaDataCache.put(new StringBuilder().append(dp.Name).toString().trim(), metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ protected JsonElement invokeRPC(String methodName, Object[] args) {

if (responseData != null) {
logger.debug("The request '{}' yields '{}'", requestData, responseData);
JsonParser parser = new JsonParser();
JsonObject resp = (JsonObject) parser.parse(new StringReader(responseData));
JsonObject resp = (JsonObject) JsonParser.parseReader(new StringReader(responseData));

result = resp.get("result");
JsonElement error = resp.get("error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class XiaomiBridgeHandler extends ConfigStatusBridgeHandler implements Xi
private static final String NO = "no";

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE);
private static final JsonParser PARSER = new JsonParser();
private static final EncryptionHelper CRYPTER = new EncryptionHelper();
private static Map<String, JsonObject> retentionInbox = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -175,7 +174,7 @@ public void onDataReceived(JsonObject message) {
}
break;
case "get_id_list_ack":
JsonArray devices = PARSER.parse(message.get("data").getAsString()).getAsJsonArray();
JsonArray devices = JsonParser.parseString(message.get("data").getAsString()).getAsJsonArray();
for (JsonElement deviceId : devices) {
String device = deviceId.getAsString();
sendCommandToBridge("read", device);
Expand Down
Loading

0 comments on commit fcc6be3

Please sign in to comment.