I’m thinking about throwing away my DB in my next project to simplify development/evolution.
One way to do it is not to leave the Objects realm at all and persist my objects by some kind of serialization. It would be nice to be able to edit the initial object state when the app is down, so a format like JSON would be great.
The problem is that JSON tools (like Java Jackson), or rather JSON itself, are not able to keep the references, so after deserializing object graph I can get more instances than I got before serialization – each reference to the same object gets new instance.
I’ve noticed JSPON but it doesn’t seem to be alive.
What do you think about such approach – isn’t it too simple to be possible? Or maybe I should use some OODB (although it would create additional configurational overhead and I want to keep it simple).
Most of the simple portable serializers (xml, json, protocol buffers) are tree serializers (not graph serializers), so you’ll see this problem a bit…
You could perhaps try using a DTO tree that doesn’t need the references? i.e. instead of:
you have (at the DTO level):
This should be usable with any tree serializer; but it does require extra (manual) processing.
There are graph-based serializers like .NET’s
DataContractSerializer(with graph-mode enabled; it is disabled by default); but this is non-portable.