use of org.springframework.boot.configurationprocessor.json.JSONObject in project spring-boot by spring-projects.
the class JsonMarshaller method write.
public void write(ConfigurationMetadata metadata, OutputStream outputStream) throws IOException {
try {
JSONObject object = new JSONObject();
JsonConverter converter = new JsonConverter();
object.put("groups", converter.toJsonArray(metadata, ItemType.GROUP));
object.put("properties", converter.toJsonArray(metadata, ItemType.PROPERTY));
object.put("hints", converter.toJsonArray(metadata.getHints()));
outputStream.write(object.toString(2).getBytes(StandardCharsets.UTF_8));
} catch (Exception ex) {
if (ex instanceof IOException) {
throw (IOException) ex;
}
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
}
throw new IllegalStateException(ex);
}
}
use of org.springframework.boot.configurationprocessor.json.JSONObject in project spring-boot by spring-projects.
the class JsonMarshaller method toValueProvider.
private ItemHint.ValueProvider toValueProvider(JSONObject object) throws Exception {
String name = object.getString("name");
Map<String, Object> parameters = new HashMap<>();
if (object.has("parameters")) {
JSONObject parametersObject = object.getJSONObject("parameters");
for (Iterator<?> iterator = parametersObject.keys(); iterator.hasNext(); ) {
String key = (String) iterator.next();
Object value = readItemValue(parametersObject.get(key));
parameters.put(key, value);
}
}
return new ItemHint.ValueProvider(name, parameters);
}
use of org.springframework.boot.configurationprocessor.json.JSONObject in project spring-boot by spring-projects.
the class JsonMarshaller method toItemDeprecation.
private ItemDeprecation toItemDeprecation(JSONObject object) throws Exception {
if (object.has("deprecation")) {
JSONObject deprecationJsonObject = object.getJSONObject("deprecation");
ItemDeprecation deprecation = new ItemDeprecation();
deprecation.setLevel(deprecationJsonObject.optString("level", null));
deprecation.setReason(deprecationJsonObject.optString("reason", null));
deprecation.setReplacement(deprecationJsonObject.optString("replacement", null));
return deprecation;
}
return object.optBoolean("deprecated") ? new ItemDeprecation() : null;
}
use of org.springframework.boot.configurationprocessor.json.JSONObject in project spring-boot by spring-projects.
the class MergeMetadataGenerationTests method writePropertyDeprecation.
private void writePropertyDeprecation(ItemMetadata... items) throws Exception {
File additionalMetadataFile = createAdditionalMetadataFile();
JSONArray propertiesArray = new JSONArray();
for (ItemMetadata item : items) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", item.getName());
if (item.getType() != null) {
jsonObject.put("type", item.getType());
}
ItemDeprecation deprecation = item.getDeprecation();
if (deprecation != null) {
JSONObject deprecationJson = new JSONObject();
if (deprecation.getReason() != null) {
deprecationJson.put("reason", deprecation.getReason());
}
if (deprecation.getReplacement() != null) {
deprecationJson.put("replacement", deprecation.getReplacement());
}
jsonObject.put("deprecation", deprecationJson);
}
propertiesArray.put(jsonObject);
}
JSONObject additionalMetadata = new JSONObject();
additionalMetadata.put("properties", propertiesArray);
writeMetadata(additionalMetadataFile, additionalMetadata);
}
use of org.springframework.boot.configurationprocessor.json.JSONObject 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);
}
Aggregations