[Simple-support] Default converter & default values
Brought to you by:
niallg
|
From: Paul J. <pa...@pa...> - 2014-02-12 20:52:14
|
Hi, Thanks for the tips on JSON. I haven't looked into them just yet; will do shortly. In the meantime, I have a couple more questions: 1) Is there a DefaultConverter I can inherit from? When writing a Converter I often find I only want to explicitly set an attribute or two, and would otherwise like to use the default conversion behaviour. It would be helpful if I could subclass something like DefaultConverter and call super.write() when I need. I'm aware that I can kind of get this behaviour using a Strategy - in fact, that's what I'm doing now. But I'd prefer to use a Converter because then I can keep serialisation logic with the class that is being serialised, rather than having a central serialisation class. 2) Is there a way to have default values? I have a few classes with a number of boolean attributes. 95% of the time these fields are at their default value and it would make the XML much more concise to omit them. The semantics I'd like are that when writing, the node is only generated if the value does not match the default. And when reading, if the node is not present, then the default is used. Any hints appreciated, Paul |