tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 JSON > FLEX JSON > Serialize JSON String to Writer Stream

Serialize JSON String to Writer Stream 

Flexjson is a lightweight java library for serializing and de-serializing java beans, maps, arrays and collections in JSON format. Get the latest binaries from https://sourceforge.net/projects/flexjson/. This requires the library flexjson-2.1.jar to be in classpath. The following example shows how to serialize a Java Object to the given Writer stream.

File Name  :  
com/bethecoder/tutorials/flexjson/tests/SerializeTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.flexjson.tests;

import java.io.StringWriter;
import java.io.Writer;
import java.util.Date;

import com.bethecoder.tutorials.flexjson.common.Student;

import flexjson.JSONSerializer;

public class SerializeTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    JSONSerializer serializer = new JSONSerializer().prettyPrint(true)
    Student stud = new Student("Sriram""Kasireddi"2"Singing"new Date());
    
    Writer out = new StringWriter();
    serializer.serialize(stud, out);
    
    System.out.println(out.toString());
  }

}
   

It gives the following output,
{
    "age": 2,
    "class": "com.bethecoder.tutorials.flexjson.common.Student",
    "dob": 1341597867390,
    "firstName": "Sriram",
    "hobby": "Singing",
    "lastName": "Kasireddi"
}


                    Print

   



Books Recommendation

 
 
bl  br