What is a serializable object?
Asked Answered
O

8

19

What is a serializable object in C#? I guess the word serializable is throwing me off more than "serializable object".

Ottavia answered 20/8, 2009 at 4:31 Comment(0)
U
30

Normally objects are random access, that is, you can specify any part of an object (property or field) and access that part directly. That's all well and fine if you're using RAM to store an object, because RAM is Random Acess Memory and is therefore suited to the job.

When you need to store your object on a medium that is not traditionally random access, for instance disk, or you need to transfer an object over a stream medium (such as the network) then the object needs to be converted into a form that is suitable to the relevant medium. This conversion process is called serialization, because the structured object is flattened or serialized, making it more amenable to being stored for the long term, or transferred over the network.

Why not just copy the bits comprising the object in RAM to disk, or send it as an opaque blob over the network? ... you may ask. A few issues:

  1. Often the format that the object is stored in memory is proprietary and therefore not suitable for public consumption--the way in which it is stored in memory is optimised for in-memory use.
  2. When an object references other objects, those references only have meaning within the context of the running application. It would not be possible to deserialize the object meaningfully unless during the serialization process, the object graph was walked and serialized accordingly. There may be a need to translate those references into a form that has meaning outside the context of an application instance.
  3. There may be an interoperability requirement between heterogeneous systems, in which case a standard means of representing the object is required (typically some form of XML is chosen for this).
Unasked answered 20/8, 2009 at 6:25 Comment(1)
As a newbie, I don't think you could of gave a better answer.Trauma
T
6

An object that can be converted to bits and stored on a medium, such as a hard drive. http://en.wikipedia.org/wiki/Serialization

Tolbert answered 20/8, 2009 at 4:32 Comment(3)
can you provide an example of an object that would NOT be serializable?Ottavia
Technically, any object that's not been serialized through some language construct or methodology is not serializable. If you want an example of an object you typically wouldn't serialize, then the general idea is "anything you don't need/want to save". In the MVC design pattern, you wouldn't typically serialize the view, as the controller should be instructing the view what to do (so you would serialize the model and the controller).Tolbert
As an example of what is not serialisable, consider something that will be very difficult, if not impossible, to reconstruct on a machine that doesn't have the same environment. For example, ResultSets aren't serialisable, because they can hold connections back to the database.Damages
R
3

Object serialization is storing the instance's state so you can reconstruct that instance again later.

In most (C# and Java), a serializable object is "marked". In Java you need to implement Serializable. In C# you need to use [Serializable].

Once the object is serialized you can store it in a file or send it over the network.

Think of it like going through every instance variable of an instance and storing its value, separated by some separator (although, it's a lot more sophisticated than that; think of what happens if you have instance variables of non-primitive types, you're gonna have to store all the values inside those, too).

One use of it would be saving a game.

Rutledge answered 20/8, 2009 at 6:42 Comment(0)
C
1

You can mark an object as [serializable] in C#, which mean that it can be converted to binary, SOAP, XML, in .net anyhow.

The beauty of this is that you can serialize an object send it across the internet, network etc then reinstate it on the other side as an object again. This can then cross machine boundaries, such as a windows machine to a Unix machine as long as the Computer on the other side is able to read the data and de-serialize it.

See this article: http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236

Consider answered 20/8, 2009 at 4:33 Comment(0)
W
1

Serializing in general means to save an objects state into a 'saveable' format (like saving to disk) so that it can be deserialized later on into an actual object. It is usually done to also send an object over the network in case of remote calls. If you dont want save and also if you dont want to send an object over the wire you can ignore the serializable part (in Java you dont implement the Serializable interface)

Whitleywhitlock answered 20/8, 2009 at 4:34 Comment(0)
M
1

Serialization :its a technique to convert object into binary format,simple object access protocol(SOAP) , or xml documents that can be easily stored ,transfered and retrieved .

In simple way serialization way that we can compress and decompress the data and transfer the data across network in a secure way.

object serialization is what ljuwaidah explained . Try this link also link text

Marabelle answered 20/8, 2009 at 7:31 Comment(0)
M
1

In addition to what has been said, I think it's important to mention that serialization of data implies giving it a well defined order (serial comes from series, which means having something lined up or in line).

For instance, serializing a graph (e.g. an RDF graph as known from the "semantic web") into a serialization format such as XML means that there must be a ruleset defining how to put the information contained in the graph into an order, so that it can later be reconstructed by applying the reverse serialization rule (deserializing it).

Moat answered 20/8, 2009 at 7:39 Comment(0)
J
0

As Java is an platform independent and it was invented for teh security purpose, all the things are possible in the form of bit. For example, we, as a user are quite understand the alphabets but it would be difficult to remember the bits of that alphabets or we can say in that Java language string. Therefore to provide the security in the networking we use the objects. As the messages are lossly coupled, to provide the security we use the objects to send or receive the messages from server or from client. Therefore as we are using the objects the objects must be serializable means they must be in the form of bits that can be easily understood by the machine. Particularly to send and receive the message is known as JMS(Java Message Service) is used. For example, one computer which is in India may want to communicate with another computer which is in the U.S. at that time, JMS service is used.

In short the serialization means to convert the strings into to the bits.

By using this we can create the Java programs such as to send the mails and receives like the mail application based on the SMTP(Simple Mail Transfer Protocol) protocol is used.

Jeanelle answered 16/3, 2017 at 19:21 Comment(1)
Why is your answer about Java when the question is about C#?Hephzipah

© 2022 - 2024 — McMap. All rights reserved.