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);
}
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;
}
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;
}
Aggregations