-
-
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
Support for indexed keys #48
Comments
Duplicate keys are not supported by properties files. This means that they would be invalid Java properties files. Multiline values are supported by properties files out of the box. Example: you can do something like this: config.prop=Sometext,\
OtherText,\
... The above will work just fine as: @Key("config.prop");
public String configProp(); Another option is to use XML. It will be released in the next version. See XML Support : <config>
<prop>
Sometext
OtherText
...
</prop>
</config> Then, for the above xml you can define the newline as separator, or define a SeparatorClass. @Separator("\n") //newline
@Key("config.prop");
public String configProp(); Indexed properties are an option to map legacy configuration files, that are using this notation. Which is quite wrong from my point of view, since properties files do support multiline values out of the box, plus owner adds support for server.0=...
server.1=...
server.3=... # server.2 is missing!
server.4=... So, I will consider this feature for future development if I get some good understanding what problem the indexed properties are solving that isn't already solved by multiline properties values (supported by default in Java properties files) and owner collections support. |
Do you support this type of XML structure, I want get elements by value. env.name this the key for each of my servers. <servers>
<env>
<name>DEV</name>
<hostname>locahost1</hostname>
<port>60000</port>
<user>myuser1</user>
<password>mypass1</password>
</env>
<env>
<name>SIT</name>
<hostname>locahost2</hostname>
<port>60010</port>
<user>myuser2</user>
<password>mypass2</password>
</env>
<env>
<name>UAT</name>
<hostname>locahost3</hostname>
<port>60020</port>
<user>myuser3</user>
<password>mypass3</password>
</env>
<env>
<name>SVP</name>
<hostname>locahost4</hostname>
<port>60030</port>
<user>myuser4</user>
<password>mypass4</password>
</env>
</servers> |
@Ronmck: No, your xml can't be supported at the moment. You can change it a follows: <servers>
<dev>
<name>DEV</name>
<hostname>locahost1</hostname>
<port>60000</port>
<user>myuser1</user>
<password>mypass1</password>
</dev>
<sit>
<name>SIT</name>
<hostname>locahost2</hostname>
<port>60010</port>
<user>myuser2</user>
<password>mypass2</password>
</sit>
<uat>
<name>UAT</name>
<hostname>locahost3</hostname>
<port>60020</port>
<user>myuser3</user>
<password>mypass3</password>
</uat>
<svp>
<name>SVP</name>
<hostname>locahost4</hostname>
<port>60030</port>
<user>myuser4</user>
<password>mypass4</password>
</svp>
</servers> This one should work fine. I want to modify OWNER to support something like this: interface MyConfig extends Config {
@Key("servers.${env}.name");
String name();
@Key("servers.${env}.hostname");
String hostname();
@Key("servers.${env}.port");
Integer port();
}
ConfigFactory.setProperty("env", "dev");
MyConfig cfg = ConfigFactory.create(MyConfig.class); This way you can select This is not working at the moment, but it is easy to implement and it will be available in the next release. |
I would like to request an option to include duplicate keys or keys with index. The config should return list/array for all the values for this key.
e.g.
server=Sometext
server=Othertext
OR
server.0=Sometext
server.1=Othertext
@key("server")
String[] server;
Thanks,
The text was updated successfully, but these errors were encountered: