Search in sources :

Example 6 with JSONObject

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

the class JsonConverter method putHintValue.

private void putHintValue(JSONObject jsonObject, Object value) throws Exception {
    Object hintValue = extractItemValue(value);
    jsonObject.put("value", hintValue);
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Example 7 with JSONObject

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

the class JsonMarshaller method read.

public ConfigurationMetadata read(InputStream inputStream) throws Exception {
    ConfigurationMetadata metadata = new ConfigurationMetadata();
    JSONObject object = new JSONObject(toString(inputStream));
    JSONArray groups = object.optJSONArray("groups");
    if (groups != null) {
        for (int i = 0; i < groups.length(); i++) {
            metadata.add(toItemMetadata((JSONObject) groups.get(i), ItemType.GROUP));
        }
    }
    JSONArray properties = object.optJSONArray("properties");
    if (properties != null) {
        for (int i = 0; i < properties.length(); i++) {
            metadata.add(toItemMetadata((JSONObject) properties.get(i), ItemType.PROPERTY));
        }
    }
    JSONArray hints = object.optJSONArray("hints");
    if (hints != null) {
        for (int i = 0; i < hints.length(); i++) {
            metadata.add(toItemHint((JSONObject) hints.get(i)));
        }
    }
    return metadata;
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) JSONArray(org.springframework.boot.configurationprocessor.json.JSONArray)

Example 8 with JSONObject

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

the class JsonMarshaller method toValueHint.

private ItemHint.ValueHint toValueHint(JSONObject object) throws Exception {
    Object value = readItemValue(object.get("value"));
    String description = object.optString("description", null);
    return new ItemHint.ValueHint(value, description);
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Example 9 with JSONObject

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

the class JsonMarshaller method toItemMetadata.

private ItemMetadata toItemMetadata(JSONObject object, ItemType itemType) throws Exception {
    String name = object.getString("name");
    String type = object.optString("type", null);
    String description = object.optString("description", null);
    String sourceType = object.optString("sourceType", null);
    String sourceMethod = object.optString("sourceMethod", null);
    Object defaultValue = readItemValue(object.opt("defaultValue"));
    ItemDeprecation deprecation = toItemDeprecation(object);
    return new ItemMetadata(itemType, name, null, type, sourceType, sourceMethod, description, defaultValue, deprecation);
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Example 10 with JSONObject

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

the class JsonMarshaller method toItemHint.

private ItemHint toItemHint(JSONObject object) throws Exception {
    String name = object.getString("name");
    List<ItemHint.ValueHint> values = new ArrayList<>();
    if (object.has("values")) {
        JSONArray valuesArray = object.getJSONArray("values");
        for (int i = 0; i < valuesArray.length(); i++) {
            values.add(toValueHint((JSONObject) valuesArray.get(i)));
        }
    }
    List<ItemHint.ValueProvider> providers = new ArrayList<>();
    if (object.has("providers")) {
        JSONArray providersObject = object.getJSONArray("providers");
        for (int i = 0; i < providersObject.length(); i++) {
            providers.add(toValueProvider((JSONObject) providersObject.get(i)));
        }
    }
    return new ItemHint(name, values, providers);
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.springframework.boot.configurationprocessor.json.JSONArray)

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