Fix for UnsupportedOperationException: JsonNull in case if device type arrives as null

This commit is contained in:
mp-loki 2018-06-16 23:23:13 -04:00
parent 1f58c1b0d6
commit 489a1a6b62

View File

@ -17,6 +17,7 @@ package org.thingsboard.server.transport.mqtt.session;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -240,7 +241,7 @@ public class GatewaySessionCtx {
private String getDeviceType(JsonElement json) throws AdaptorException { private String getDeviceType(JsonElement json) throws AdaptorException {
JsonElement type = json.getAsJsonObject().get("type"); JsonElement type = json.getAsJsonObject().get("type");
return type == null ? DEFAULT_DEVICE_TYPE : type.getAsString(); return type == null || type instanceof JsonNull ? DEFAULT_DEVICE_TYPE : type.getAsString();
} }
private JsonElement getJson(MqttPublishMessage mqttMsg) throws AdaptorException { private JsonElement getJson(MqttPublishMessage mqttMsg) throws AdaptorException {