so i was looking up how java handles loading xml files, since i was considering using them for data stuff, and uh the answer seems to be "badly".
so there's this thing called JAXB, the java architecture for xml binding, which is apparently the accepted method, and it just like, automagically dumps out all state in a java object, recursively. what if you don't want your xml files to have a 1:1 correspondence with internal object state? well, then you make an interstitial object that has the correct names and values so that the automagical serialization produces an xml file more to your liking, and then you convert your normal objects into interstitial objects, serialize them, and repeat the process in reverse to deserialize. there are also some custom hooks in the xml parser thing to optionally drop specifically-named fields, or store certain values as attributes instead of sub-elements, but it seems unbelievably crusty.
for a while i was like "this seems incredibly dense and obnoxious to use, which is weird because i remember using a thing with minecraft that was a lot easier", and after a little digging i remembered that that was when i was using the
(it's not that i have anything against automated serializers/deserializers, it's just it seems to encourage thinking of data as an opaque glob, and introduces huge issues if the object ever gains or loses internal properties, since that invalidates all your old data.)
so anyway i'll probably just do all this using json, which is... not ideal (there is no javascript here at all, so, why json) but unless there's a non-awful xml lib i'm just gonna go the path of least resistance here.
so there's this thing called JAXB, the java architecture for xml binding, which is apparently the accepted method, and it just like, automagically dumps out all state in a java object, recursively. what if you don't want your xml files to have a 1:1 correspondence with internal object state? well, then you make an interstitial object that has the correct names and values so that the automagical serialization produces an xml file more to your liking, and then you convert your normal objects into interstitial objects, serialize them, and repeat the process in reverse to deserialize. there are also some custom hooks in the xml parser thing to optionally drop specifically-named fields, or store certain values as attributes instead of sub-elements, but it seems unbelievably crusty.
for a while i was like "this seems incredibly dense and obnoxious to use, which is weird because i remember using a thing with minecraft that was a lot easier", and after a little digging i remembered that that was when i was using the
gson
lib to serialize/deserialize json, where you just write a decoder func for type T and that means you can then make a Deserializer<T>
which has a default function to parse a file into a value of that type.(it's not that i have anything against automated serializers/deserializers, it's just it seems to encourage thinking of data as an opaque glob, and introduces huge issues if the object ever gains or loses internal properties, since that invalidates all your old data.)
so anyway i'll probably just do all this using json, which is... not ideal (there is no javascript here at all, so, why json) but unless there's a non-awful xml lib i'm just gonna go the path of least resistance here.