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.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 10 API Review; Where Next.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Lecture 31 File I/O -Part 2 COMP1681 / SE15 Introduction to Programming.
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
File I/O in Java CS 311, Winter File Basics Recall that a file is block structured. What does this mean? What happens when an application opens.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
15-Jul-15 JSON. JSON example “JSON” stands for “JavaScript Object Notation” Despite the name, JSON is a (mostly) language-independent way of specifying.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
CSC – Java Programming II Lecture 9 January 30, 2002.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
M1G Introduction to Database Development 6. Building Applications.
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Copyright © Curt Hill Sounds, Resource Packs, JSON What more would you want?
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
JAVA I/O © EnhanceEdu, IIIT Hyderabad. Contents 3/29/2010EnhanceEdu, IIIT - H 2  Command Line I/O  File Class  Streams  Byte Streams [Low level and.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
JSON Java Script Object Notation Copyright © 2013 Curt Hill.
Copyright Curt Hill Variables What are they? Why do we need them?
Server - Client Communication Getting data from server.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
CIS 270—App Dev II Big Java Chapter 19 Files and Streams.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
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.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Project Scenario for OpX. High-level Overview In the Test GUI Controller, opXController, for the opX command there is conceptually a call to an appropriate.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
OVERVIEW AND PARSING JSON. What is JSON JavaScript Object Notation Used to format data Commonly used in Web as a vehicle to describe data being sent between.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
JSON. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation It’s really language.
Tools of the trade J SON, M AVEN, A PACHE COMMON Photo from
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
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
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Apache Avro CMSC 491 Hadoop-Based Distributed Computing Spring 2016 Adam Shook.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
XML and Distributed Applications By Quddus Chong Presentation for CS551 – Fall 2001.
Chapter No. : 1 Introduction to Java.
Exporting and Importing Data
JSON Crash Course Traversy Media.
Exporting and Importing Data
Scope, Objects, Strings, Numbers
Programming Language Concepts (CIS 635)
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Introduction to Python
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Built in Fairfield County: Front End Developers Meetup
Python Primer 1: Types and Operators
CSE 331 Memento Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Department of Computer Science Cal State East Bay, Hayward, CA
Presentation transcript:

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 a network) and "resurrected" later in the same or another computer. We will focus on machine to machine communication. – Can be used for persistence

Serialization Convert language defined types and user defined types to standard intermediate form – Primitive types: e.g. integer, short, long, double, float, boolean, char, array – Collections: ArrayList, Map, Sets, etc. – User defined typed: Classes and enums Must solve the graph traversal problem for types that are recursive

Data Interchange Format “Binary” XML – The standard for web applications – We will use this in our project JSON – Can be used for inter-language communication – Becoming popular and another standard for web applications

Data Interchange Format “Binary” – Java Serialization – Only works in Java to Java Communication – Faster – Not human readable – Mechanism For user defined types extend “Serializable” ObjectInputStream ObjectOutputStream

Data Interchange Format JSON – Text Based – “Human Readable” – Supposedly simpler than XML – All Objects can converted to a standard form by using a combination of the following conversions and annotations Number (double precision) String (double-quoted Unicode, with backslash escaping) Boolean (true or false) Array (an ordered sequence of values, comma-separated and enclosed in square brackets; the values do not need to be of the same type) Object (an unordered collection of key:value pairs with the ':' character separating the key and the value, comma-separated and enclosed in curly braces; the keys must be strings and should be distinct from each other) null (empty JSON code for Java – GSON GSON – FLEXJSON FLEXJSON – XStream XStream

Data Interchange Format XML – Text based – “Human Readable” – XML structures tend to mimic the data structures of the encoding language – Implemented techniques often only work when the source language and destination language are the same – Encoding/Decoding takes time

XML Software There are many, here are two – JAXB – built into java Not as easy as it could be Tutorials – From Oracle From Oracle – Small and Simple Small and Simple – – Xstream Very simple – especially compared to others The one you might want to consider Xstream – Easy Example Easy Example

Get the Xstream Jar Download the most recent jar. – Go to here.here. – Click on the most recent version (as of this time it is 1.4.3) – Download the main jar in the directory (currently it is xstream jar) – Install it in your build path

Use Xstream Declarations import com.thoughtworks.xstream.Xstream; import com.toughtworks.xstream.io.xml.DomDriver private Xstream xmlStream; //variable declaration xmlStream = new Xstream(new DomDriver());

Use Xstream Client Side Client Side – Object result = xmlStream.fromXML(connection.getInputStream()); Used when transforming the results of a GET request to an HTTP Server The connection is of type HttpURLConnection returned from executing “openConnection()” on an object of type URL. Used to execute the GET request and getting the results. – xmlStream.toXML(object, connection.getOutputStream()); Used to send an object (usually a command) to an HTTP server

Use Xstream Server Side Client Side – SomeType type = (SomeType)xmlStream.fromXML(exchange.getRequestBody()); The exchange is of type HttpExchange which is an abstract representation of an instance of communication from a client to this server. The “getRequestBody()” returns the information as an InputStream – xmlStream.toXML(responseObject, exchange.getResponseBody()); Used to return an answer to the client “getResponseBody()” returns an OutputStream

Use Xstream To And From a File or To A String Object object = xmlStream.fromXML(file) The file is of type File Converts the contents of an XML file to an object The object is usually type cast to the appropriate type. xmlStream.toXML(object, fileOutputStream); Used to convert an object to an XML representation and writes it to a FileOutputStream (a file) String string = xmlStream.toXML(object); Converts an object to its XML representation