views:

116

answers:

5

I've seen the term "serialized" all over, but never explained. Please explain what that means.

+4  A: 

Serialization is the process of taking an object instance and converting it to a format in which it can be transported across a network or persisted to storage (such as a file or database). The serialized format contains the object's state information.

Deserialization is the process of using the serialized state to reconstruct the object from the serialized state to its original state.

Mitch Wheat
I thought you refused to "do the work of the OP"? And yet, here's an answer from you. Funny how it goes. ;)
jalf
@jalf: " Funny how it goes" - sure is. you got the accepted answer despite answering 2 minutes later. touche. ;)
Mitch Wheat
heh ;) (15 chars padding)
jalf
+2  A: 

real simple explanation, serialization is the act of taking something that is in memory like an instance of a class (object) and transforming into a structure suitable for transport or storage.

A common example is XML serialization for use in web services - I have an instance of a class on the server and need to send it over the web to you, I first serialize it into xml which means to create an xml version of that data in the class, once in xml I can use a transport like HTTP to easily send it.

There are several forms of serialization like XML or JSON.

keithwarren7
+2  A: 

Serialization usually refers to the process of converting an abstract datatype to a stream of bytes (You sometimes serialize to text, XML or CSV or other formats as well. The important thing is that it is a simple format that can be read/written without understanding the abstract objects that the data represents). When saving data to a file, or transmitting over a network, you can't just store a MyClass object, you're only able to store bytes. So you need to take all the data necessary to reconstruct your object, and turn that into a sequence of bytes that can be written to the destination device, and at some later point read back and deserialized, reconstructing your object.

jalf
an abstract datatype? more like a concrete....
Mitch Wheat
Class objects are abstract datatypes. Abstract as in "not a primitive data type, but something representing an abstract concept". A `Car` class is an abstract datatype. It represents something abstract in the program. There are no cars in it. Just data providing the abstraction of one. And that abstraction must be torn down in order to serialize it. You can't store a car to a file, but you can store the data necessary to reconstruct the `Car` class instance.
jalf
@jalf: you are using terms in a way contrary to what is generally accepted.
Mitch Wheat
No I'm not. I'm not talking about an abstract class, which I agree is something entirely different. An abstract datatype is pretty much a more general term for a class (except it nicely covers the equivalents in classless languages). A class is an abstraction, and it is a datatype. Calling it an abstract datatype is not an idea I just came up with. :)
jalf
+2  A: 

There are (at least) two entirely different meanings to serialization. One is turning a data structure in memory into a stream of bits, so it can be written to disk and reconstituted later, or transmitted over a network connection and used on another machine, etc.

The other meaning relates to serial vs. parallel execution -- i.e. ensuring that only one thread of execution does something at a time. For example, if you're going to read, modify and write a variable, you need to ensure that one thread completes a read, modify, write sequence before another can start it.

Jerry Coffin
I'm glad someone mentioned the other meaning of 'serialization' - I can remember being confused the first time I came across the "spit an object out to a file" meaning since I had been using it to mean "critical sections" for a long while before that.
Michael Burr
I think you mean Sequential rather than serialised...
Mitch Wheat
No - "serialized" can also be used to mean "serializing *access* to data or code". "Marshalling" is the term I used for getting an object's data to/from a file (or other stream) before the term "serialization" came to be used for that in the context of Java/.NET (at least for me).
Michael Burr
+2  A: 

What they said. The word "serial" refers to the fact that the data bytes must be put into some standardized order to be written to a serial storage device, like a file output stream or serial bus. In practice, the raw bytes seldom suffice. For example, a memory address from the program that serializes the data structure may be invalid in the program that reconstructs the object from the stored data. So a protocol is required. There have been many, many standards and implementations over the years. I remember one from the mid 80's called XDR, but it was not the first.

Jive Dadson