Search in sources :

Example 6 with JSONArray

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

the class MergeMetadataGenerationTests method writeAdditionalMetadata.

private void writeAdditionalMetadata(ItemMetadata... metadata) throws Exception {
    TestJsonConverter converter = new TestJsonConverter();
    File additionalMetadataFile = createAdditionalMetadataFile();
    JSONObject additionalMetadata = new JSONObject();
    JSONArray properties = new JSONArray();
    for (ItemMetadata itemMetadata : metadata) {
        properties.put(converter.toJsonObject(itemMetadata));
    }
    additionalMetadata.put("properties", properties);
    writeMetadata(additionalMetadataFile, additionalMetadata);
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) JSONArray(org.springframework.boot.configurationprocessor.json.JSONArray) File(java.io.File) TestJsonConverter(org.springframework.boot.configurationprocessor.metadata.TestJsonConverter) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata)

Example 7 with JSONArray

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

the class JsonConverter method toJsonArray.

JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
    JSONArray jsonArray = new JSONArray();
    List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.isOfItemType(itemType)).sorted(ITEM_COMPARATOR).collect(Collectors.toList());
    for (ItemMetadata item : items) {
        if (item.isOfItemType(itemType)) {
            jsonArray.put(toJsonObject(item));
        }
    }
    return jsonArray;
}
Also used : JSONArray(org.springframework.boot.configurationprocessor.json.JSONArray)

Example 8 with JSONArray

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

the class JsonConverter method extractItemValue.

private Object extractItemValue(Object value) {
    Object defaultValue = value;
    if (value.getClass().isArray()) {
        JSONArray array = new JSONArray();
        int length = Array.getLength(value);
        for (int i = 0; i < length; i++) {
            array.put(Array.get(value, i));
        }
        defaultValue = array;
    }
    return defaultValue;
}
Also used : JSONArray(org.springframework.boot.configurationprocessor.json.JSONArray) JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Aggregations

JSONArray (org.springframework.boot.configurationprocessor.json.JSONArray)8 JSONObject (org.springframework.boot.configurationprocessor.json.JSONObject)7 File (java.io.File)3 ItemMetadata (org.springframework.boot.configurationprocessor.metadata.ItemMetadata)2 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 ConfigurationMetadata (org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata)1 ItemDeprecation (org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)1 TestJsonConverter (org.springframework.boot.configurationprocessor.metadata.TestJsonConverter)1