Is using serialization a good idea?

There are several risks associated with serialization, including incompatible changes. If incompatible changes occur in serializable classes, we cannot de-serialize it even with a static finite long field serialVersionUID.

So what are the alternatives to serialization? XML? If there is any alternative, is there any use of serialization in real projects?

+3
source share
3 answers

Of course, there are alternatives to Java serialization: XML (as you noted); JSON Protobuf; anything you would like to use instead.

. , - . , " ". , .

+3

, , - .

, , :

  • , , - , . , /, - , - "". "" , java python; .

  • , , - /. , , . , , , ( ). , json- ( json, ...); , comms ad-hoc- .

  • " ", - , , , " " , , ( ). docbook (jaxb (1) , (3); "" .

- , . , xml; json (2).

, - (1) , . (2) , ( (1), ); , (3).

+2

The answer depends on your goal. If you send data between Java processes, the default Java serialization engine may work fine.

However, for storing data, especially data that people might want to view or modify, the Java serialization mechanism is poorly suited.

There are a number of great XML-java serialization libraries that I really prefer when readable / editable output is required.

Two big ones: XStream and JAXB

+1
source

All Articles