Note that there are some explanatory texts on larger screens.

plurals
  1. POJava "settings object", serialization/deserialization
    text
    copied!<p>(<s>Code is for Android</s> Actually, I need code to be portable between Android and Java SE.)</p> <p>I want to have a "settings" class with various game settings, like</p> <pre><code>public int map_size; public String server_name; </code></pre> <p>etc.</p> <p>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).</p> <p>I want to be able to</p> <ol> <li><p>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).</p></li> <li><p>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).</p></li> </ol> <p>1 is achievable by using reflection. I thought Java annotations for class members would be perfect for 2:</p> <pre><code>@Setting(id = "server_name", name = "Server title", default = "Server0") public String server_name; </code></pre> <p>But it looks like (user-defined) annotations don't work in Android yet - code using them crashes the compiler...</p> <p><b>What would be the easiest way to store the meta-data about the settings</b> (or another way to approach all this)?</p> <ul> <li><p>Store information about settings in some external XML file?</p></li> <li><p>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.</p></li> <li><p>?</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload