Files
spring-boot-rest/spring-boot-properties/src/main/java/com/baeldung/properties/JsonPropertySourceFactory.java
2019-08-11 18:30:21 +05:30

21 lines
737 B
Java

package com.baeldung.properties;
import java.io.IOException;
import java.util.Map;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonPropertySourceFactory implements PropertySourceFactory {
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
Map readValue = new ObjectMapper().readValue(resource.getInputStream(), Map.class);
return new MapPropertySource("json-property", readValue);
}
}