-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Nested collections/arrays #37
Comments
Hi @alexeyr. This is possible (with the version available on the
public class Server {
private final String name;
private final Integer port;
public Server(String spec) { // you need to parse spec, ok... some work to do, but not that bad...
String[] split = spec.split(":", -1);
name = split[0];
if (split.lenght > =2)
port = Integer.valueOf(split[1]);
else
port = 80;
}
public String getName() { return name; }
public Integer getPort() { return port; }
}
public interface ServerConfig extends Config {
Server[] servers;
// or
List<Server> servers;
} Another option I am thinking about is this: public class Server {
private final String name;
private final Integer port;
public Server(String name, Integer port) {
this.name = name;
this.port = port;
}
public String getName() { return name; }
public Integer getPort() { return port; }
}
public interface ServerConfig extends Config {
@ConverterClass(ServerConverter.class)
Server[] servers;
// or
List<Server> servers;
}
public class ServerConverter extends Converter<Server> {
public Server convert(Method targetMethod, String text) {
String[] split = text.split(":", -1);
String name = split[0];
Integer port = 80;
if (split.lenght >= 2)
port = Integer.valueOf(split[1]);
return new Server(name, port);
}
} The I have a different idea about config nesting, and I don't find it to be suitable for collections/arrays. Notice that collections and arrays are already available in the Opinions? |
I did consider this approach, but it doesn't scale well if you need more than 2 or 3 properties, or default values. |
I'll consider this when I'll implement the nesting in config. Maybe it will be implemented as per your suggestion. This implementation makes sense. |
Related to #2: support for collections (or arrays) of complex types. E.g.
and in the properties file
should produce an array of 2 servers (or map with keys
"1"
and"2"
).The text was updated successfully, but these errors were encountered: