public class DefaultJSONWriter extends Object implements JSONWriter
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 |
DefaultJSONWriter.JSONAnnotationFinder |
ENUM_AS_BEAN_DEFAULT
Constructor and Description |
---|
DefaultJSONWriter() |
Modifier and Type | Method and Description |
---|---|
protected void |
add(char c) |
protected void |
add(Object obj) |
protected boolean |
add(String name,
Object value,
Method method,
boolean hasData) |
protected void |
array(Iterator it,
Method method) |
protected void |
array(Object object,
Method method) |
protected void |
bean(Object object)
Instrospect bean and serialize its properties
|
protected void |
bool(boolean b) |
protected void |
date(Date date,
Method method) |
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) |
protected void |
process(Object object,
Method method)
Serialize object into json
|
protected void |
processCustom(Object object,
Method method)
Serialize custom object into json
|
void |
setCacheBeanInfo(boolean cacheBeanInfo) |
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()) |
void |
setExcludeProxyProperties(boolean excludeProxyProperties) |
void |
setExcludeProxyProperties(String excludeProxyProperties) |
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 void setExcludeProxyProperties(String excludeProxyProperties)
public String write(Object object) throws JSONException
write
in interface JSONWriter
object
- Object to be serialized into JSONJSONException
- in case of error during serializepublic String write(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties) throws JSONException
write
in interface JSONWriter
object
- Object to be serialized into JSONexcludeProperties
- Patterns matching properties to ignoreincludeProperties
- Patterns matching properties to includeexcludeNullProperties
- enable/disable excluding of null propertiesJSONException
- in case of error during serializeprotected void value(Object object, Method method) throws JSONException
object
- Object to be serialized into JSONmethod
- methodJSONException
- in case of error during serializeprotected void process(Object object, Method method) throws JSONException
object
- Object to be serialized into JSONmethod
- methodJSONException
- in case of error during serializeprotected void processCustom(Object object, Method method) throws JSONException
object
- objectmethod
- methodJSONException
- in case of error during serializeprotected void bean(Object object) throws JSONException
object
- objectJSONException
- in case of error during serializeprotected 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
enumeration
- the enumJSONException
- in case of error during serializeprotected 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)
obj
- the object to escapeprotected void add(Object obj)
protected void add(char c)
protected void unicode(char c)
c
- character to be encodedpublic void setIgnoreHierarchy(boolean ignoreHierarchy)
setIgnoreHierarchy
in interface JSONWriter
public void setEnumAsBean(boolean enumAsBean)
setEnumAsBean
in interface JSONWriter
enumAsBean
- true to serialize an enum as a bean instead of as a name=value
pair (default=false)public void setDateFormatter(String defaultDateFormat)
setDateFormatter
in interface JSONWriter
public void setCacheBeanInfo(boolean cacheBeanInfo)
setCacheBeanInfo
in interface JSONWriter
public void setExcludeProxyProperties(boolean excludeProxyProperties)
setExcludeProxyProperties
in interface JSONWriter
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.