Browse Source

fix + refactoring

pull/2436/head
Bohdan Smetaniuk 6 years ago
parent
commit
37cb35c99b
  1. 16
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/adaptor/JsonConverter.java

16
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/adaptor/JsonConverter.java

@ -133,15 +133,21 @@ public class JsonConverter {
.build(); .build();
} }
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonObject) throws JsonSyntaxException { public static PostAttributeMsg convertToAttributesProto(JsonElement jsonElement) throws JsonSyntaxException {
if (jsonObject.isJsonObject()) { if (jsonElement.isJsonObject()) {
PostAttributeMsg.Builder result = PostAttributeMsg.newBuilder(); PostAttributeMsg.Builder result = PostAttributeMsg.newBuilder();
List<KeyValueProto> keyValueList = parseProtoValues(jsonObject.getAsJsonObject().getAsJsonObject("kv")); List<KeyValueProto> keyValueList = null;
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject.has("kv") && jsonObject.has("scope")) {
keyValueList = parseProtoValues(jsonObject.getAsJsonObject("kv"));
result.setScope(jsonObject.getAsJsonPrimitive("scope").getAsString());
} else {
keyValueList = parseProtoValues(jsonObject);
}
result.addAllKv(keyValueList); result.addAllKv(keyValueList);
result.setScope(jsonObject.getAsJsonObject().getAsJsonPrimitive("scope").getAsString());
return result.build(); return result.build();
} else { } else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject); throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonElement);
} }
} }

Loading…
Cancel
Save