ConfigJSR
ConfigJSR copied to clipboard
Support tree-structure config source
From Tomas:
Find a way to resolve the following usecase: Yaml config like this:
sockets:
- name: name1
port: 80
- name:
name2
port: 9090
address: “192.168.1.1"
API expectation: Config.asList(“sockets”, SocketConfig.class) [Tomas]
sockets.0.name="name1"
sockets.0.port=80
sockets.0.address=
sockets.1.name="name2"
sockets.1.port= 9090
sockets.1.address=“192.168.1.1"
@Configuration
public class SocketConfig{
private String name;
private int port;
private String address;
}
It should be possible to make a YAML/JSON ConfigSource that turns the hierarchy that's possible in those formats into the classic "dotted-notation" used in Java properties files. Many JSON parsers provide this functionality out-of-the-box.
Like Akka Typesafe config !
Socket[] serverSockets = config.getValue("sockets", SocketConfig[].class);
In today's hangout, we come into conclusion on the requirement of the need of introducing another way to opt in property files, maybe using prefix saying javax-configxxx to opt in the tree-structure files e.g. javax-config.json or javax-config.yaml
@tomas-langer @sebadiaz and @Emily-Jiang met today and agreed the following mapping strategy from tree structure to config name: sockets.0.name="name1" sockets.0.port=80 sockets.0.address=
sockets.1.name="name2" sockets.1.port= 9090 sockets.1.address=“192.168.1.1"
................ We need to think about how to inject the configure property to an object, similar like: @Configuration public class SocketConfig{ private String name; private int port; private String address; }
@ConfigProperty(cacheFor=3)
public interface SocketConfig{
@ConfigProperty(name="sockets")
String getName();
int getPort();
String getAddress();
}