What are object serialization and deserialization?
What difference does serialization have with normal techniques like reading an object's properties and then filling a DataRow's columns with them and finally saving the DataRow in DB?
To serialize an object means to convert its state to a byte stream so way that the byte stream can be reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses implements either the java. io. Serializable interface or its subinterface, java.
Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file or store in DB for later usage. Deserialization is the process of converting Object stream to actual Java Object to be used in our program.
Serialization is a conversion of the state of a Java object to a byte stream and Deserialization is the reverse of it i.e. conversion of a byte stream to corresponding Java object. A serialized object can be stored in files, external sources, databases etc and can also be transferred over networks.
An ObjectInputStream deserializes objects and primitive data written using an ObjectOutputStream. It creates an ObjectInputStream that reads from the specified InputStream. It reads an object from the input stream.
Serialization generally refers to creating a version of the data (rather than the objects) that can be used for storage (perhaps in a file), for transfer over a network, or perhaps just for transfer between processes / AppDomain
s /etc on a single machine.
Serialization typically means writing the data as a string (think: xml / json) or as raw binary (a byte[]
etc). Deserialization is the reverse process; taking the raw data (from a file, from an incoming network socket, etc) and reconstructing the object model.
The difference between using a db is that it has no intrinsic tabular layout, and no real tie to a database; the data can be any shape, and tends to map more closely to the object-oriented layout than to the rows/columns nature of tables.
Most platforms have a range of serialization tools. For example, it sounds like you're talking about .NET - so BinaryFormatter
(.NET-specific), XmlSerializer
, DataContractSerializer
, Json.NET and protobuf-net / dotnet-protobufs would all qualify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With