Which is the best alternative for Java Serialization? -


i'm working on project needs persist kind of object (of implementation don't have control) these objects recovered afterwards.

we can't implement orm because can't restrict users of our library @ development time.

our first alternative serialize java default serialization had lot of trouble recovering objects when users started pass different versions of same object (attributes changed types, names, ...).

we have tried xmlencoder class (transforms object xml), have found there lack of functionality (doesn't support enums example).

finally, tried jaxb impose our users annotate classes.

any alternative?

the easiest thing still use serialization, imo, put more thought serialized form of classes (which ought anyway). instance:

  1. explicitly define serialuid.
  2. define own serialized form appropriate.

the serialized form part of class' api , careful thought should put design.

i won't go lot of details, since pretty have said comes effective java. i'll instead, refer it, chapters serialization. warns problems you're running into, , provides proper solutions problem:

http://www.amazon.com/effective-java-2nd-joshua-bloch/dp/0321356683


with said, if you're still considering non-serialization approach, here couple:

xml marshalling

as many has pointed out option, think you'll still run same problems backward compatibility. however, xml marshalling, you'll catch these right away, since frameworks may checks during initialization.

conversion to/from yaml

this idea have been toying with, liked yaml format (at least custom tostring() format). really, difference you'd marshalling yaml instead of xml. benefit that yaml more human readable xml. same restrictions apply.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -