Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tree-structure config source #77

Open
Emily-Jiang opened this issue Jul 19, 2018 · 7 comments
Open

Support tree-structure config source #77

Emily-Jiang opened this issue Jul 19, 2018 · 7 comments

Comments

@Emily-Jiang
Copy link
Member

Emily-Jiang commented Jul 19, 2018

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
Copy link
Member Author

Emily-Jiang commented Jul 19, 2018

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

@smoyer64
Copy link

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.

@sebadiaz
Copy link

Like Akka Typesafe config !

@struberg
Copy link
Contributor

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

@Emily-Jiang
Copy link
Member Author

Emily-Jiang commented Aug 16, 2018

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
Copy link
Member Author

Emily-Jiang commented Jan 31, 2019

@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
Copy link
Member Author

Emily-Jiang commented Mar 14, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants