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 for Map objects #41

Open
lviggiano opened this issue Jul 10, 2013 · 2 comments
Open

Support for Map objects #41

lviggiano opened this issue Jul 10, 2013 · 2 comments

Comments

@lviggiano
Copy link
Collaborator

sample property:

something.foo=1
something.bar=2
something.baz=3

sample class:

interface MyConfig extends Config {
    Map<String, Integer> something(); 
}

something() should return a map containing: foo=1, bar=2, baz=3

@chipu
Copy link

chipu commented Oct 11, 2013

Another format could be:
something=key1:value1 key2:value2
defining then 2 types of separators (" " and ":")

@lviggiano
Copy link
Collaborator Author

@chipu that would be pretty easy (see this example). But I think it wouldn't be powerful as I wish: converting things to Map<String,String> would bring some advantage, but since OWNER has a rich set of converter I think that it should be possible to convert to Map<String,Anything> which sounds more convenient. We had some discussions here #52 .

Also I think that a Config object returning a Map<String, ?> could be better mapped to a Config object returning a nested Config object:

interface MyConfig extends Config {
  @DefaultValue("key1:value1 key2:value2")
  Map<String, String> map();
}

// would be equivalent, but more convenient, if expressed as:

interface MyMap extends Config {
  @DefaultValue("value1");
  String key1();

  @DefaultValue("value2");
  String key2();
}

interface MyConfig extends Config {
    MyMap map();
}

Basically a Config object can be seen as a map, where the method name is the key, and the returned value is the value. The advantage is that the compiler can check that the key is valid, and the return type matches, and IDE can also apply refactoring.

BTW I see the Map support feature related to the #2

Thanks for your feedback @chipu .

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

No branches or pull requests

2 participants