Search in sources :

Example 1 with JSONObject

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

the class MergeMetadataGenerationTests method writeAdditionalHints.

private void writeAdditionalHints(ItemHint... hints) throws Exception {
    TestJsonConverter converter = new TestJsonConverter();
    File additionalMetadataFile = createAdditionalMetadataFile();
    JSONObject additionalMetadata = new JSONObject();
    additionalMetadata.put("hints", converter.toJsonArray(Arrays.asList(hints)));
    writeMetadata(additionalMetadataFile, additionalMetadata);
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) File(java.io.File) TestJsonConverter(org.springframework.boot.configurationprocessor.metadata.TestJsonConverter)

Example 2 with JSONObject

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

the class MergeMetadataGenerationTests method mergingOfAdditionalMetadata.

@Test
void mergingOfAdditionalMetadata() throws Exception {
    File metaInfDirectory = new File(getCompiler().getOutputLocation(), "META-INF");
    metaInfDirectory.mkdirs();
    File additionalMetadataFile = new File(metaInfDirectory, "additional-spring-configuration-metadata.json");
    additionalMetadataFile.createNewFile();
    JSONObject property = new JSONObject();
    property.put("name", "foo");
    property.put("type", "java.lang.String");
    property.put("sourceType", AdditionalMetadata.class.getName());
    JSONArray properties = new JSONArray();
    properties.put(property);
    JSONObject additionalMetadata = new JSONObject();
    additionalMetadata.put("properties", properties);
    FileWriter writer = new FileWriter(additionalMetadataFile);
    writer.append(additionalMetadata.toString(2));
    writer.flush();
    writer.close();
    ConfigurationMetadata metadata = compile(SimpleProperties.class);
    assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
    assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject) FileWriter(java.io.FileWriter) JSONArray(org.springframework.boot.configurationprocessor.json.JSONArray) File(java.io.File) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) Test(org.junit.jupiter.api.Test)

Example 3 with JSONObject

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

the class JsonConverter method getItemHintValue.

private JSONObject getItemHintValue(ItemHint.ValueHint value) throws Exception {
    JSONObject result = new JSONObject();
    putHintValue(result, value.getValue());
    result.putOpt("description", value.getDescription());
    return result;
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Example 4 with JSONObject

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

the class JsonConverter method toJsonObject.

private JSONObject toJsonObject(ItemHint hint) throws Exception {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", hint.getName());
    if (!hint.getValues().isEmpty()) {
        jsonObject.put("values", getItemHintValues(hint));
    }
    if (!hint.getProviders().isEmpty()) {
        jsonObject.put("providers", getItemHintProviders(hint));
    }
    return jsonObject;
}
Also used : JSONObject(org.springframework.boot.configurationprocessor.json.JSONObject)

Example 5 with JSONObject

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

the class JsonConverter method putDefaultValue.

private void putDefaultValue(JSONObject jsonObject, Object value) throws Exception {
    Object defaultValue = extractItemValue(value);
    jsonObject.put("defaultValue", defaultValue);
}
Also used : 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