Search in sources :

Example 16 with JSONObject

use of org.springframework.boot.configurationprocessor.json.JSONObject in project spring-boot by spring-projects.

the class JsonConverter method getItemHintProvider.

private JSONObject getItemHintProvider(ItemHint.ValueProvider provider) throws Exception {
    JSONObject result = new JSONObject();
    result.put("name", provider.getName());
    if (provider.getParameters() != null && !provider.getParameters().isEmpty()) {
        JSONObject parameters = new JSONObject();
        for (Map.Entry<String, Object> entry : provider.getParameters().entrySet()) {
            parameters.put(entry.getKey(), extractItemValue(entry.getValue()));
        }
        result.put("parameters", parameters);
    }
    return result;
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) Map(java.util.Map)

Example 17 with JSONObject

use of org.springframework.boot.configurationprocessor.json.JSONObject in project spring-boot by spring-projects.

the class JsonConverter method toJsonObject.

JSONObject toJsonObject(ItemMetadata item) throws Exception {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", item.getName());
    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);
    }
    ItemDeprecation deprecation = item.getDeprecation();
    if (deprecation != null) {
        // backward compatibility
        jsonObject.put("deprecated", true);
        JSONObject deprecationJsonObject = new JSONObject();
        if (deprecation.getLevel() != null) {
            deprecationJsonObject.put("level", deprecation.getLevel());
        }
        if (deprecation.getReason() != null) {
            deprecationJsonObject.put("reason", deprecation.getReason());
        }
        if (deprecation.getReplacement() != null) {
            deprecationJsonObject.put("replacement", deprecation.getReplacement());
        }
        jsonObject.put("deprecation", deprecationJsonObject);
    }
    return jsonObject;
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Aggregations

JSONObject (org.springframework.boot.configurationprocessor.json.JSONObject)17 JSONArray (org.springframework.boot.configurationprocessor.json.JSONArray)5 File (java.io.File)4 ItemMetadata (org.springframework.boot.configurationprocessor.metadata.ItemMetadata)2 TestJsonConverter (org.springframework.boot.configurationprocessor.metadata.TestJsonConverter)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 ConfigurationMetadata (org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata)1 ItemDeprecation (org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)1