public class JSONWriter extends Object
Serializes an object into JavaScript Object Notation (JSON). If cyclic references are detected they will be nulled out.
Modifier and Type | Class and Description |
---|---|
protected static class |
JSONWriter.JSONAnnotationFinder |
Modifier and Type | Field and Description |
---|---|
static boolean |
ENUM_AS_BEAN_DEFAULT
By default, enums are serialised as name=value pairs
|
Constructor and Description |
---|
JSONWriter() |
Modifier and Type | Method and Description |
---|---|
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 BeanInfo |
getBeanInfo(Class<?> clazz) |
protected BeanInfo |
getBeanInfoIgnoreHierarchy(Class<?> clazz) |
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 |
setDateFormatter(String defaultDateFormat) |
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) |
public static final boolean ENUM_AS_BEAN_DEFAULT
public String write(Object object) throws JSONException
object
- Object to be serialized into JSONJSONException
public String write(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties) throws JSONException
object
- Object to be serialized into JSONJSONException
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 BeanInfo getBeanInfoIgnoreHierarchy(Class<?> clazz) throws IntrospectionException
IntrospectionException
protected BeanInfo getBeanInfo(Class<?> clazz) throws IntrospectionException
IntrospectionException
protected Object getBridgedValue(Method baseAccessor, Object value) throws InstantiationException, IllegalAccessException
protected void enumeration(Enum enumeration) throws JSONException
JSONException
protected boolean shouldExcludeProperty(PropertyDescriptor prop) throws SecurityException, NoSuchFieldException
protected String expandExpr(int i)
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 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)public void setDateFormatter(String defaultDateFormat)
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.