org.apache.struts2.json
Class JSONUtil

java.lang.Object
  extended by org.apache.struts2.json.JSONUtil

public class JSONUtil
extends java.lang.Object

Wrapper for JSONWriter with some utility methods.


Nested Class Summary
static interface JSONUtil.ClassVisitor
          Realizes the visit(Class) method called by vistInterfaces for all encountered classes/interfaces
 
Field Summary
static java.lang.String REGEXP_PATTERN
           
static java.lang.String WILDCARD_PATTERN
           
 
Constructor Summary
JSONUtil()
           
 
Method Summary
static java.util.Set<java.lang.String> asSet(java.lang.String commaDelim)
           
static java.lang.Object deserialize(java.io.Reader reader)
          Deserializes a object from JSON
static java.lang.Object deserialize(java.lang.String json)
          Deserializes a object from JSON
static boolean isGzipInRequest(javax.servlet.http.HttpServletRequest request)
           
static java.lang.reflect.Method[] listSMDMethods(java.lang.Class clazz, boolean ignoreInterfaces)
          List visible methods carrying the
static java.util.List<java.util.regex.Pattern> processIncludePatterns(java.util.Set<java.lang.String> includePatterns, java.lang.String type)
           
static java.lang.String serialize(java.lang.Object object)
          Serializes an object into JSON.
static java.lang.String serialize(java.lang.Object object, java.util.Collection<java.util.regex.Pattern> excludeProperties, java.util.Collection<java.util.regex.Pattern> includeProperties, boolean ignoreHierarchy, boolean excludeNullProperties)
          Serializes an object into JSON, excluding any properties matching any of the regular expressions in the given collection.
static java.lang.String serialize(java.lang.Object object, java.util.Collection<java.util.regex.Pattern> excludeProperties, java.util.Collection<java.util.regex.Pattern> includeProperties, boolean ignoreHierarchy, boolean enumAsBean, boolean excludeNullProperties)
          Serializes an object into JSON, excluding any properties matching any of the regular expressions in the given collection.
static void serialize(java.io.Writer writer, java.lang.Object object)
          Serializes an object into JSON to the given writer.
static void serialize(java.io.Writer writer, java.lang.Object object, java.util.Collection<java.util.regex.Pattern> excludeProperties, java.util.Collection<java.util.regex.Pattern> includeProperties, boolean excludeNullProperties)
          Serializes an object into JSON to the given writer, excluding any properties matching any of the regular expressions in the given collection.
static boolean visitInterfaces(java.lang.Class aClass, JSONUtil.ClassVisitor visitor)
          Visit all the interfaces realized by the specified object, its superclasses and its interfaces

Visitation is performed in the following order: aClass aClass' interfaces the interface's superclasses (interfaces) aClass' superclass superclass' interfaces superclass' interface's superclasses (interfaces) super-superclass and so on

The Object base class is base excluded.

static void writeJSONToResponse(SerializationParams serializationParams)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REGEXP_PATTERN

public static final java.lang.String REGEXP_PATTERN
See Also:
Constant Field Values

WILDCARD_PATTERN

public static final java.lang.String WILDCARD_PATTERN
See Also:
Constant Field Values
Constructor Detail

JSONUtil

public JSONUtil()
Method Detail

serialize

public static java.lang.String serialize(java.lang.Object object)
                                  throws JSONException
Serializes an object into JSON.

Parameters:
object - to be serialized
Returns:
JSON string
Throws:
JSONException

serialize

public static java.lang.String serialize(java.lang.Object object,
                                         java.util.Collection<java.util.regex.Pattern> excludeProperties,
                                         java.util.Collection<java.util.regex.Pattern> includeProperties,
                                         boolean ignoreHierarchy,
                                         boolean excludeNullProperties)
                                  throws JSONException
Serializes an object into JSON, excluding any properties matching any of the regular expressions in the given collection.

Parameters:
object - to be serialized
excludeProperties - Patterns matching properties to exclude
ignoreHierarchy - whether to ignore properties defined on base classes of the root object
Returns:
JSON string
Throws:
JSONException

serialize

public static java.lang.String serialize(java.lang.Object object,
                                         java.util.Collection<java.util.regex.Pattern> excludeProperties,
                                         java.util.Collection<java.util.regex.Pattern> includeProperties,
                                         boolean ignoreHierarchy,
                                         boolean enumAsBean,
                                         boolean excludeNullProperties)
                                  throws JSONException
Serializes an object into JSON, excluding any properties matching any of the regular expressions in the given collection.

Parameters:
object - to be serialized
excludeProperties - Patterns matching properties to exclude
ignoreHierarchy - whether to ignore properties defined on base classes of the root object
enumAsBean - whether to serialized enums a Bean or name=value pair
Returns:
JSON string
Throws:
JSONException

serialize

public static void serialize(java.io.Writer writer,
                             java.lang.Object object)
                      throws java.io.IOException,
                             JSONException
Serializes an object into JSON to the given writer.

Parameters:
writer - Writer to serialize the object to
object - object to be serialized
Throws:
java.io.IOException
JSONException

serialize

public static void serialize(java.io.Writer writer,
                             java.lang.Object object,
                             java.util.Collection<java.util.regex.Pattern> excludeProperties,
                             java.util.Collection<java.util.regex.Pattern> includeProperties,
                             boolean excludeNullProperties)
                      throws java.io.IOException,
                             JSONException
Serializes an object into JSON to the given writer, excluding any properties matching any of the regular expressions in the given collection.

Parameters:
writer - Writer to serialize the object to
object - object to be serialized
excludeProperties - Patterns matching properties to ignore
Throws:
java.io.IOException
JSONException

deserialize

public static java.lang.Object deserialize(java.lang.String json)
                                    throws JSONException
Deserializes a object from JSON

Parameters:
json - string in JSON
Returns:
desrialized object
Throws:
JSONException

deserialize

public static java.lang.Object deserialize(java.io.Reader reader)
                                    throws JSONException
Deserializes a object from JSON

Parameters:
reader - Reader to read a JSON string from
Returns:
deserialized object
Throws:
JSONException - when IOException happens

writeJSONToResponse

public static void writeJSONToResponse(SerializationParams serializationParams)
                                throws java.io.IOException
Throws:
java.io.IOException

asSet

public static java.util.Set<java.lang.String> asSet(java.lang.String commaDelim)

listSMDMethods

public static java.lang.reflect.Method[] listSMDMethods(java.lang.Class clazz,
                                                        boolean ignoreInterfaces)
List visible methods carrying the

Parameters:
ignoreInterfaces - if true, only the methods of the class are examined. If false, annotations on every interfaces' methods are examined.

visitInterfaces

public static boolean visitInterfaces(java.lang.Class aClass,
                                      JSONUtil.ClassVisitor visitor)
Visit all the interfaces realized by the specified object, its superclasses and its interfaces

Visitation is performed in the following order: aClass aClass' interfaces the interface's superclasses (interfaces) aClass' superclass superclass' interfaces superclass' interface's superclasses (interfaces) super-superclass and so on

The Object base class is base excluded. Classes/interfaces are only visited once each

Parameters:
aClass - the class to start recursing upwards from
visitor - this vistor is called for each class/interface encountered
Returns:
true if all classes/interfaces were visited, false if it was exited early as specified by a ClassVisitor result

isGzipInRequest

public static boolean isGzipInRequest(javax.servlet.http.HttpServletRequest request)

processIncludePatterns

public static java.util.List<java.util.regex.Pattern> processIncludePatterns(java.util.Set<java.lang.String> includePatterns,
                                                                             java.lang.String type)


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.