From 46e59503ec4b3d8bea4c789f763882ab629750f4 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Tue, 1 Jan 2019 12:07:31 +0100 Subject: [PATCH] Use JSONObject.putOpt in JsonConverter Closes gh-15595 --- .../metadata/JsonConverter.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java index 874c022744..4deeffc505 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/JsonConverter.java @@ -1,5 +1,5 @@ /* - * 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);