(Code is for Android Actually, I need code to be portable between Android and Java SE.)
I want to have a "settings" class with various game settings, like
public int map_size;
public String server_name;
etc.
The data needs to be accessed fairly frequently (so members, not a key-value map), and from time to time de/serialized in some standard way (mainly to send it through network).
I want to be able to
Serialize and deserialize the object into XML or JSON, without having to explicitly write the code for every member (but still having some degree of control over the format).
Define some (constant) meta-data about every member (default value, GUI name, XML identifier, ...), in a way that allows for easy modification in the source code (I want to be able to add a new meta-property, define a default value for it, and not have to specify it everywhere else).
1 is achievable by using reflection. I thought Java annotations for class members would be perfect for 2:
@Setting(id = "server_name", name = "Server title", default = "Server0")
public String server_name;
But it looks like (user-defined) annotations don't work in Android yet - code using them crashes the compiler...
What would be the easiest way to store the meta-data about the settings (or another way to approach all this)?
Store information about settings in some external XML file?
Store it in a Java data structure, with content defined in the code? Defining the data in this way somehow seems very unwieldy, especially compared to keyword arguments of annotations.
?