com.plumtree.portalpages.rest.utils
Class JSONSerializer

java.lang.Object
  extended by com.plumtree.portalpages.rest.utils.JSONSerializer

public class JSONSerializer
extends java.lang.Object

Author:
rozhang Serializes an XPHashtable or IXP list to JSON notation

Field Summary
protected  XPHashtable m_object
           
 
Constructor Summary
JSONSerializer(XPHashtable jsonObject)
           
 
Method Summary
protected  java.lang.String AddPadding(int level)
          Helper for adding the proper amount of indentation
 java.lang.String GenerateStringRepresentation(boolean addPrefix)
          Main parsing function
protected  java.lang.String GetStringValue(java.lang.Object val, java.lang.String name)
          Returns JSON string representation of a value.
protected  java.lang.String ParseArray(IXPList values, int level)
          Generate JSON string representation for Array node The generated output will be in the following format: [ value1, value2, value3, ...
protected  java.lang.String ParseHashTable(XPHashtable map, int level)
          Generate JSON String representation for node with child nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_object

protected XPHashtable m_object
Constructor Detail

JSONSerializer

public JSONSerializer(XPHashtable jsonObject)
Method Detail

GenerateStringRepresentation

public java.lang.String GenerateStringRepresentation(boolean addPrefix)
Main parsing function

Parameters:
addPrefix - Protects the JSON string from rewrites/pollution/hijacking hacks by prefixing the generated JSON with '{} && '. The prefix is skipped by the eval function when interpreting the JSON as data, i.e. transforming the JSON into an object with properties but turns the JSON into unexecutable javascript to protect against various CSRF vunerabilities
Returns:

ParseHashTable

protected java.lang.String ParseHashTable(XPHashtable map,
                                          int level)
Generate JSON String representation for node with child nodes. The generated output will be in the following format: { property1: value2, property2: value2, property3: value3, ... }

Parameters:
map -
level - The depth from the top where top is 0
Returns:

ParseArray

protected java.lang.String ParseArray(IXPList values,
                                      int level)
Generate JSON string representation for Array node The generated output will be in the following format: [ value1, value2, value3, ... ]

Parameters:
values -
level -
Returns:

AddPadding

protected java.lang.String AddPadding(int level)
Helper for adding the proper amount of indentation

Parameters:
level -
Returns:

GetStringValue

protected java.lang.String GetStringValue(java.lang.Object val,
                                          java.lang.String name)
Returns JSON string representation of a value. Strings are escape encoded

Parameters:
val -
name -
Returns:



Copyright © 2002,2003,2004,2005 Plumtree Software, Inc., All Rights Reserved.