|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.struts2.json.JSONWriter
public class JSONWriter
Serializes an object into JavaScript Object Notation (JSON). If cyclic references are detected they will be nulled out.
Nested Class Summary | |
---|---|
protected static class |
JSONWriter.JSONAnnotationFinder
|
Field Summary | |
---|---|
static boolean |
ENUM_AS_BEAN_DEFAULT
By default, enums are serialzied as name=value pairs |
Constructor Summary | |
---|---|
JSONWriter()
|
Method Summary | |
---|---|
protected void |
add(char c)
Add char to buffer |
protected void |
add(Object obj)
Add object to buffer |
protected boolean |
add(String name,
Object value,
Method method,
boolean hasData)
Add name/value pair to buffer |
protected void |
array(Iterator it,
Method method)
Add array to buffer |
protected void |
array(Object object,
Method method)
Add array to buffer |
protected void |
bean(Object object)
Instrospect bean and serialize its properties |
protected void |
bool(boolean b)
Add boolean to buffer |
protected void |
date(Date date,
Method method)
Add date to buffer |
protected void |
enumeration(Enum enumeration)
Instrospect an Enum and serialize it as a name/value pair or as a bean including all its own properties |
protected String |
expandExpr(int i)
|
protected String |
expandExpr(String property)
|
protected Method |
findBaseAccessor(Class clazz,
Method accessor)
|
protected Object |
getBridgedValue(Method baseAccessor,
Object value)
|
protected void |
map(Map map,
Method method)
Add map to buffer |
protected void |
process(Object object,
Method method)
Serialize object into json |
protected void |
processCustom(Object object,
Method method)
Serialize custom object into json |
void |
setEnumAsBean(boolean enumAsBean)
If true, an Enum is serialized as a bean with a special property _name=name() as all as all other properties defined within the enum. If false, an Enum is serialized as a name=value pair (name=name()) |
protected String |
setExprStack(String expr)
|
void |
setIgnoreHierarchy(boolean ignoreHierarchy)
|
protected boolean |
shouldExcludeProperty(PropertyDescriptor prop)
|
protected boolean |
shouldExcludeProperty(String expr)
|
protected void |
string(Object obj)
escape characters |
protected void |
unicode(char c)
Represent as unicode |
protected void |
value(Object object,
Method method)
Detect cyclic references |
String |
write(Object object)
|
String |
write(Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean excludeNullProperties)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean ENUM_AS_BEAN_DEFAULT
Constructor Detail |
---|
public JSONWriter()
Method Detail |
---|
public String write(Object object) throws JSONException
object
- Object to be serialized into JSON
JSONException
public String write(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties) throws JSONException
object
- Object to be serialized into JSON
JSONException
protected void value(Object object, Method method) throws JSONException
JSONException
protected void process(Object object, Method method) throws JSONException
JSONException
protected void processCustom(Object object, Method method) throws JSONException
JSONException
protected void bean(Object object) throws JSONException
JSONException
protected Object getBridgedValue(Method baseAccessor, Object value) throws InstantiationException, IllegalAccessException
InstantiationException
IllegalAccessException
protected Method findBaseAccessor(Class clazz, Method accessor)
protected void enumeration(Enum enumeration) throws JSONException
JSONException
protected boolean shouldExcludeProperty(PropertyDescriptor prop) throws SecurityException, NoSuchFieldException
SecurityException
NoSuchFieldException
protected String expandExpr(int i)
protected String expandExpr(String property)
protected String setExprStack(String expr)
protected boolean shouldExcludeProperty(String expr)
protected boolean add(String name, Object value, Method method, boolean hasData) throws JSONException
JSONException
protected void map(Map map, Method method) throws JSONException
JSONException
protected void date(Date date, Method method)
protected void array(Iterator it, Method method) throws JSONException
JSONException
protected void array(Object object, Method method) throws JSONException
JSONException
protected void bool(boolean b)
protected void string(Object obj)
protected void add(Object obj)
protected void add(char c)
protected void unicode(char c)
c
- character to be encodedpublic void setIgnoreHierarchy(boolean ignoreHierarchy)
public void setEnumAsBean(boolean enumAsBean)
enumAsBean
- true to serialize an enum as a bean instead of as a name=value
pair (default=false)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |