Saturday, December 8, 2012

Serialization at Client Side

Serialization is a process of converting Object into Raw data.In javascript many times we need to convert Raw data into Object and viceversa.
For example, when we submit a form, Its data needs to be sent to the server in JSON form.

  • Serialization is the process of turning any object into a string.
  • De-serialization turns that string back into a native object.
JSON is a lightweight data-interchange format inspired by JavaScript object literal notation.
Certain framework provides method to convert Model, Form data into JSON.
For eg backbone.js provieds following
  • Model.toJSON for serialization
  • Model.parse for de-serialization

    Once we have JSON library we can use the two most useful methods whcih are availble:
    • JSON.stringify(obj) — converts an JavaScript object to a JSON string
    • JSON.parse(str) — converts a JSON string back to a JavaScript object
     Both are really cool features which we can use where we are interarcting with web services and serer is going to use the object to marshal into a Java Object.

    1 comment: