Commit 4f207d24 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #15595 from dreis2211

* pr/15595:
  Use JSONObject.putOpt in JsonConverter
parents 19caff67 46e59503
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -62,10 +62,10 @@ class JsonConverter {
public JSONObject toJsonObject(ItemMetadata item) throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", item.getName());
putIfPresent(jsonObject, "type", item.getType());
putIfPresent(jsonObject, "description", item.getDescription());
putIfPresent(jsonObject, "sourceType", item.getSourceType());
putIfPresent(jsonObject, "sourceMethod", item.getSourceMethod());
jsonObject.putOpt("type", item.getType());
jsonObject.putOpt("description", item.getDescription());
jsonObject.putOpt("sourceType", item.getSourceType());
jsonObject.putOpt("sourceMethod", item.getSourceMethod());
Object defaultValue = item.getDefaultValue();
if (defaultValue != null) {
putDefaultValue(jsonObject, defaultValue);
......@@ -111,7 +111,7 @@ class JsonConverter {
private JSONObject getItemHintValue(ItemHint.ValueHint value) throws Exception {
JSONObject result = new JSONObject();
putHintValue(result, value.getValue());
putIfPresent(result, "description", value.getDescription());
result.putOpt("description", value.getDescription());
return result;
}
......@@ -137,13 +137,6 @@ class JsonConverter {
return result;
}
private void putIfPresent(JSONObject jsonObject, String name, Object value)
throws Exception {
if (value != null) {
jsonObject.put(name, value);
}
}
private void putHintValue(JSONObject jsonObject, Object value) throws Exception {
Object hintValue = extractItemValue(value);
jsonObject.put("value", hintValue);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment