fix + refactoring

This commit is contained in:
Bohdan Smetaniuk 2020-07-14 17:06:21 +03:00
parent 2b14fa3634
commit 37cb35c99b

View File

@ -133,15 +133,21 @@ public class JsonConverter {
.build();
}
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonObject) throws JsonSyntaxException {
if (jsonObject.isJsonObject()) {
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonElement) throws JsonSyntaxException {
if (jsonElement.isJsonObject()) {
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.setScope(jsonObject.getAsJsonObject().getAsJsonPrimitive("scope").getAsString());
return result.build();
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject);
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonElement);
}
}