Chapter 10. Serializing Objects

I l @ ve RuBoard

The previous chapter highlighted the problems associated with transporting data of varying lengths and formats over a network. The main issue is using a structure to represent the data that a sender and a receiver both agree on and that is unambiguous ”to avoid little endian vs. big endian questions, for example. The same problems can arise when you persist objects to a data store: Applications that write data must use a format that other applications can interpret correctly. (The term data store in this context can mean a database, a collection of files, or some other set of data.)

Often, you'll need to convert an object from the internal format used in an application to a format suitable for persistence or transportation. The process of converting an object into such a form is called serialization . The reverse process is called deserialization . Serialization is an important part of any distributed system. For example, in the Microsoft .NET Framework, serialization is employed when you use the .NET Remoting architecture (covered in Chapter 11) or access Web services (described in Part V).

The Java language supports serialization as a mechanism for marshaling objects between processes, and it uses its own internal format. Java serialization is used by Remote Method Invocation (RMI) to pass objects by value across process boundaries. You can serialize and deserialize objects manually through the readObject and writeObject methods of the ObjectInputStream and ObjectOutputStream classes, respectively, in the java.io package of the JDK. You can exploit native Java serialization from J# to consume and produce serialized streams that can be written or read by other Java applications. However, the .NET Framework offers its own serialization technologies that can you can use from any of the languages that execute in the common language runtime. These are

  • Binary serialization

    A compact format that's useful for sharing data between managed applications.

  • XML serialization

    A more open but less dense format that is typically used when you don't want to restrict the applications that can read the data to those built using the .NET Framework SDK. XML serialization is the method of choice when you build Web services, for example.

In this chapter, we'll examine how serialization works and how to use the classes and features of the .NET Framework to implement binary and XML serialization. You'll also learn how to customize how data is serialized.

I l @ ve RuBoard


Microsoft Visual J# .NET (Core Reference)
Microsoft Visual J# .NET (Core Reference) (Pro-Developer)
ISBN: 0735615500
EAN: 2147483647
Year: 2002
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net