Serialization What is Serialization Serialization is the process of converting an object, or a connected graph of objects, stored within computer memory,

Slides:



Advertisements
Similar presentations
Improving Learning Object Description Mechanisms to Support an Integrated Framework for Ubiquitous Learning Scenarios María Felisa Verdejo Carlos Celorrio.
Advertisements

Reading and Writing Text Files Svetlin Nakov Telerik Corporation
Slide 10.1 Advanced Programming 2004, based on LY Stefanus’s Slides Object Serialization Object serialization: the process of converting an object into.
SOAP Quang Vinh Pham Simon De Baets Université Libre de Bruxelles1.
History Leading to XHTML
.Net Remoting Pooja Panjala 06/17/10. Agenda What is.net Remoting? Explanation of terms Architecture Implementation of Remoting Sample example.net Security.
C# and Windows Programming Application Domains and Remoting.
Object Oriented Programming Files and Streams Dr. Mike Spann
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
Serialization objects created in a program reside in RAM through references object o; heap stack content.
Portable binary serialization, the Google way
SaxStore: a n aspect oriented persistence library for Java based on SAX events Riccardo Solmi University of Bologna May 2001.
History, Architecture, and Implementation of the CLR Serialization and Formatter Classes Peter de Jong April 24, 2003.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
ASP.NET Programming with C# and SQL Server First Edition
Creating Sequential-Access File  Serializable attribute indicates to the compiler that objects of a class can be serialized– written to or read from a.
Sequential-access file Create, read and write an object into a sequential-access file Serialize and deserialize the object to write and read from a data.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
7-Aug-15 Serialization and XML Pat Palmer What is serialization? “The process of converting an object (or a graph of objects) into a linear sequence.
Windows Programming Using C# Windows Services, Serialization, and Isolated Storage.
.NET Framework Introduction: Metadata
1 Binary Files ผศ. ดร. หมัดอามีน หมันหลิน Faculty of IST, MUT
Avro Apache Course: Distributed class Student ID: AM Name: Azzaya Galbazar
Apps Meeting 2010 Travis Armstrong Cyle Nelson January 2010 Advanced C# Customization Training.
Microsoft Visual Studio 2010 Muhammad Zubair MS (FAST-NU) Experience: 5+ Years Contact:- Cell#:
HeuristicLab. Motivation  less memory pressure no DOM single pass linear process  less developer effort no interfaces to implement  modularity & flexibility.
Lector: Aliyev H.U. Lecture №5 Telecommunication network software design with.NET. Using streams for network programming TASHKENT UNIVERSITY OF INFORMATION.
Software Design 13.1 XML: Another TLA or the Future? XML is eXtensible Markup Language  It's a w3c standard.
Serialization  What is Serialization?  System.Serialization  Scenarios in Serialization  Basic Serialization  Custom Serialization.
Microsoft Visual Studio 2010 Muhammad Zubair MS (FAST-NU) Experience: 5+ Years Contact:- Cell#:
 2006 Pearson Education, Inc. All rights reserved Files and Streams.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
Object Persistence and Object serialization CSNB534 Asma Shakil.
Computer Programming TCP1224 Chapter 13 Sequential File Access.
Lecture 19 Serialization Richard Gesick. Serialization Sometimes it is easier to read or write entire objects than to read and write individual fields.
Chapter 4 Introduction to Classes, Objects, Methods and strings
CIS 270—App Dev II Big Java Chapter 19 Files and Streams.
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
Object Serialization. Sequential-access Text Files Sequential-access files store records In order by the record-key field Java imposes no structure on.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
Web Services from 10,000 feet Part I Tom Perkins NTPCUG CertSIG XML Web Services.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
Extending SharePoint through Web Parts and ASP.NET 최승현 대리 한국마이크로소프트.
1 Copyright © 2011 Tata Consultancy Services Limited TCS Internal.
.NET XML Web Services by Joe Mayo Mayo Software Consulting
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
CHAPTER 9 File Storage Shared Preferences SQLite.
1 CSE 331 Memento Pattern and Serialization slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Metropolia 2013 C# programming and .NET framework
Advanced .NET Programming II 6th Lecture
IS444: Modern tools for applications development
18 Files and Streams.
Serialization.
IS444: Modern tools for applications development
Lectures 12 Files & Streams Dr. Eng. Ibrahim El-Nahry.
Overview of Hadoop MapReduce MapReduce is a soft work framework for easily writing applications which process vast amounts of.
MSIS 670: Object-Oriented Software Engineering
.NET and .NET Core 10. Enabling Contracts Pan Wuming 2017.
Serialization and Deserialization Bullet points from Head First Java, Ch Dec-18 serialization.ppt.
Files & Streams.
Object Oriented Programming
CSE 331 Memento Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Fundaments of Game Design
How to organize and document your classes
Quiz Points 3 Rules Raise your hand if you know the question
Map Reduce, Types, Formats and Features
Presentation transcript:

Serialization What is Serialization Serialization is the process of converting an object, or a connected graph of objects, stored within computer memory, into a linear sequence of bytes Use the sequence of bytes in several ways: – Send it to another process – Send it to the clipboard, to be browsed or used by another application – Send it to another machine – Send it to a file on disk

Serialization Object Graph What is an object graph? – An object graph is a set of objects with some set of references to each other – The most obvious problem is how to represent the links between the objects in the Serialized stream Cat Mouse Duck Dog Horse

Serialization How Serialization Works Because run-time metadata 'knows' about each object's layout in memory, and its field and property definitions, you can serialize objects automatically, without having to write code to serialize each field The serialized stream might be encoded using XML, or a compact binary representation The format is decided by the the Formatter object that you call: – Binary – SOAP – Custom

Serializaiton Example - VideoLibrary using System; namespace VideoLibrary { [Serializable] public enum Genre { Drama, Comedy, Western, ScienceFiction, Horror, Family }; [Serializable] public class VideoInfo { public string Title { get; set; } public Genre Category { get; set; } public string Director { get; set; } public int Year { get; set; } public TimeSpan Duration { get; set; } public string Review { get; set; } } Worksheet 4 from

Serializaiton Example - VideoLibrary namespace VideoLibrary { public partial class MyVideoLibraryForm : Form { List videoLib = new List (); … private void saveLibraryToolStripMenuItem_Click(object sender, EventArgs e) { if (this.saveLibraryDialog.ShowDialog() == DialogResult.OK) { XmlSerializer s = new XmlSerializer(videoLib.GetType()); using (TextWriter w = new StreamWriter(saveLibraryDialog.FileName)) { s.Serialize(w, videoLib); } Worksheet 4 from File->Save menu

Serializaiton Example - VideoLibrary private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (this.openLibraryDialog.ShowDialog() == DialogResult.OK) { XmlSerializer s = new XmlSerializer(videoLib.GetType()); using (TextReader reader = new StreamReader(openLibraryDialog.FileName)) { List newVideos = (List )s.Deserialize(reader); foreach( VideoInfo video in newVideos) bindingVideoLib.Add(video); } Worksheet 4 from File->Import menu

Serialization Scenarios Persistence Remoting-By-Value Remoting-By-Reference Transacted Persistence

Serialization Basic Serialization A Type is NOT Serializable unless Type is specifically marked as Serializable The Serializable Attribute The Non-Serializable Attribute [Serializable] public class MyClass {} [Serializable] public class MyClass { [NotSerialized] int _cashSize; }

Serialization It is easy to write the individual fields of a record object to a file For example, we can create a record that stores information about a student – Name – Address – ID number – Course enrolled for – etc We can output each field of this record to a file (either text or binary)

Serialization StudentInfo Name Address ID number Course Info Record file string string int string

Serialization In this example, any program that needs to read the file needs to know the format of the data – 2 strings, an int and then a string – Also whether each item is on a separate line.NET serialization allows complete objects to be read or written with a single statement (.NET does the plumbing for you using reflection). A serialized object is an object represented as a sequence of bytes. Information is stored about the data types of the objects instance fields as well as their values – Allows the object to be reconstructed (de- serialized) from the sequence of bytes.

Serialization StudentInfo Name Address ID number Course Info Record file StudentInfo object

Serialization To serialize an object, the object class needs to be marked with the [Serializable] attribute or needs to implement the ISerializable interface Requires the System.Runtime.Serialization namespace Also we require a formatter to serialize/de- serialize the object before writing to or reading from file – IFormatter - BinaryFormatter – XMLSerializer (why is this not an IFormatter?)

Serialization ISerializable Interface Customize the serialization process If a class implements ISerializable, that interface will always be called in preference to default serialization. The ISerializable interface only contains one method: void GetObjectData (SerializationInfo info, StreamingContext context); And an implied constructor that may be private. private (SerializationInfo info, StreamingContext)

Serialization Additional Attributes The serialization framework allows you to also specify methods to be called when an instance is being deserialized, after it is deserialized, before it is serialized, etc. – [OnDeserialized] – see the MSDN example.MSDN example

Serialization IDeserializationEventListener If an object implements IDeserializationEventListener, the serialization infrastructure will call that class‘ OnDeserialization method as soon as the entire graph has been deserialized and all fix- ups completed Provide a reasonable opportunity for objects that need to do fix-ups based on the state of their children

Serialization Binary serialization is limited as only.NET applications can deserialize the data stream For more general inter-operability especially across a network, xml serialization is used – xml is text based and self descibing and universal – Comprised name/attribute pairs – xml serialization easy to implement and uses text streams

Serialization We need to insert xml tags into our StudentInfo class – Only public properties and fields can be serialized [XmlRoot("studentInfo")] public class StudentInfo { [XmlAttribute("name")] public string Name; [XmlAttribute("address")] public string Address; [XmlAttribute("course")] public string CourseInfo; [XmlAttribute("id")] private int ID; public StudentInfo() { } public StudentInfo(String n, String a, String ci, int id) { Name = n; Address = a; CourseInfo = ci; ID = id; }