ConfigJSR icon indicating copy to clipboard operation
ConfigJSR copied to clipboard

Support tree-structure config source

Open Emily-Jiang opened this issue 7 years ago • 7 comments

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]

Emily-Jiang avatar Jul 19 '18 14:07 Emily-Jiang

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;
}

Emily-Jiang avatar Jul 19 '18 15:07 Emily-Jiang

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.

smoyer64 avatar Jul 22 '18 17:07 smoyer64

Like Akka Typesafe config !

sebadiaz avatar Jul 30 '18 08:07 sebadiaz

Socket[] serverSockets = config.getValue("sockets", SocketConfig[].class);

struberg avatar Aug 16 '18 14:08 struberg

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

Emily-Jiang avatar Aug 16 '18 14:08 Emily-Jiang

@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; }

Emily-Jiang avatar Jan 31 '19 15:01 Emily-Jiang

@ConfigProperty(cacheFor=3)
public interface SocketConfig{
   @ConfigProperty(name="sockets")
   String getName();
    int getPort();
    String getAddress();
}

Emily-Jiang avatar Mar 14 '19 15:03 Emily-Jiang