Spring cache YAML config format support. #346

pull/382/head
Nikita 9 years ago
parent 90e8fed310
commit eabfc460e3

@ -193,20 +193,25 @@
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.6.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.3</version>
<version>2.6.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
<version>2.6.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<version>2.6.3</version>
<version>2.6.5</version>
<scope>provided</scope>
</dependency>
<dependency>

@ -154,4 +154,69 @@ public class CacheConfig {
return new CacheConfigSupport().toJSON(configs);
}
/**
* Read config objects stored in YAML format from <code>String</code>
*
* @param content
* @return
* @throws IOException
*/
public static Map<String, CacheConfig> fromYAML(String content) throws IOException {
return new CacheConfigSupport().fromYAML(content);
}
/**
* Read config objects stored in YAML format from <code>InputStream</code>
*
* @param inputStream
* @return
* @throws IOException
*/
public static Map<String, CacheConfig> fromYAML(InputStream inputStream) throws IOException {
return new CacheConfigSupport().fromYAML(inputStream);
}
/**
* Read config objects stored in YAML format from <code>File</code>
*
* @param file
* @return
* @throws IOException
*/
public static Map<String, CacheConfig> fromYAML(File file) throws IOException {
return new CacheConfigSupport().fromYAML(file);
}
/**
* Read config objects stored in YAML format from <code>URL</code>
*
* @param url
* @return
* @throws IOException
*/
public static Map<String, CacheConfig> fromYAML(URL url) throws IOException {
return new CacheConfigSupport().fromYAML(url);
}
/**
* Read config objects stored in YAML format from <code>Reader</code>
*
* @param reader
* @return
* @throws IOException
*/
public static Map<String, CacheConfig> fromYAML(Reader reader) throws IOException {
return new CacheConfigSupport().fromYAML(reader);
}
/**
* Convert current configuration to YAML format
*
* @return
* @throws IOException
*/
public static String toYAML(Map<String, CacheConfig> configs) throws IOException {
return new CacheConfigSupport().toYAML(configs);
}
}

@ -24,33 +24,60 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
public class CacheConfigSupport {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper jsonMapper = new ObjectMapper();
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
public Map<String, CacheConfig> fromJSON(String content) throws IOException {
return mapper.readValue(content, new TypeReference<Map<String, CacheConfig>>() {});
return jsonMapper.readValue(content, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromJSON(File file) throws IOException {
return mapper.readValue(file, new TypeReference<Map<String, CacheConfig>>() {});
return jsonMapper.readValue(file, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromJSON(URL url) throws IOException {
return mapper.readValue(url, new TypeReference<Map<String, CacheConfig>>() {});
return jsonMapper.readValue(url, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromJSON(Reader reader) throws IOException {
return mapper.readValue(reader, new TypeReference<Map<String, CacheConfig>>() {});
return jsonMapper.readValue(reader, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromJSON(InputStream inputStream) throws IOException {
return mapper.readValue(inputStream, new TypeReference<Map<String, CacheConfig>>() {});
return jsonMapper.readValue(inputStream, new TypeReference<Map<String, CacheConfig>>() {});
}
public String toJSON(Map<String, CacheConfig> configs) throws IOException {
return mapper.writeValueAsString(configs);
return jsonMapper.writeValueAsString(configs);
}
public Map<String, CacheConfig> fromYAML(String content) throws IOException {
return yamlMapper.readValue(content, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromYAML(File file) throws IOException {
return yamlMapper.readValue(file, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromYAML(URL url) throws IOException {
return yamlMapper.readValue(url, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromYAML(Reader reader) throws IOException {
return yamlMapper.readValue(reader, new TypeReference<Map<String, CacheConfig>>() {});
}
public Map<String, CacheConfig> fromYAML(InputStream inputStream) throws IOException {
return yamlMapper.readValue(inputStream, new TypeReference<Map<String, CacheConfig>>() {});
}
public String toYAML(Map<String, CacheConfig> configs) throws IOException {
return yamlMapper.writeValueAsString(configs);
}
}

Loading…
Cancel
Save