Package org.apache.struts2.json
Class DefaultJSONWriter
java.lang.Object
org.apache.struts2.json.DefaultJSONWriter
- All Implemented Interfaces:
JSONWriter
Serializes an object into JavaScript Object Notation (JSON). If cyclic references are detected they will be nulled out.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface org.apache.struts2.json.JSONWriter
ENUM_AS_BEAN_DEFAULT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
add
(char c) protected void
protected boolean
protected void
protected void
protected void
Instrospect bean and serialize its propertiesprotected void
bool
(boolean b) protected void
protected void
enumeration
(Enum enumeration) Instrospect an Enum and serialize it as a name/value pair or as a bean including all its own propertiesprotected 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
protected void
Serialize object into jsonprotected void
processCustom
(Object object, Method method) Serialize custom object into jsonvoid
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
protected boolean
shouldExcludeProperty
(String expr) protected void
escape charactersprotected void
unicode
(char c) Represent as unicodeprotected void
Detect cyclic referenceswrite
(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties)
-
Constructor Details
-
DefaultJSONWriter
public DefaultJSONWriter()
-
-
Method Details
-
setExcludeProxyProperties
-
write
- Specified by:
write
in interfaceJSONWriter
- Parameters:
object
- Object to be serialized into JSON- Returns:
- JSON string for object
- Throws:
JSONException
- in case of error during serialize
-
write
public String write(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties) throws JSONException - Specified by:
write
in interfaceJSONWriter
- Parameters:
object
- Object to be serialized into JSONexcludeProperties
- Patterns matching properties to ignoreincludeProperties
- Patterns matching properties to includeexcludeNullProperties
- enable/disable excluding of null properties- Returns:
- JSON string for object
- Throws:
JSONException
- in case of error during serialize
-
value
Detect cyclic references- Parameters:
object
- Object to be serialized into JSONmethod
- method- Throws:
JSONException
- in case of error during serialize
-
process
Serialize object into json- Parameters:
object
- Object to be serialized into JSONmethod
- method- Throws:
JSONException
- in case of error during serialize
-
processCustom
Serialize custom object into json- Parameters:
object
- objectmethod
- method- Throws:
JSONException
- in case of error during serialize
-
bean
Instrospect bean and serialize its properties- Parameters:
object
- object- Throws:
JSONException
- in case of error during serialize
-
getBeanInfoIgnoreHierarchy
- Throws:
IntrospectionException
-
getBeanInfo
- Throws:
IntrospectionException
-
getBridgedValue
protected Object getBridgedValue(Method baseAccessor, Object value) throws InstantiationException, IllegalAccessException -
findBaseAccessor
-
enumeration
Instrospect an Enum and serialize it as a name/value pair or as a bean including all its own properties- Parameters:
enumeration
- the enum- Throws:
JSONException
- in case of error during serialize
-
shouldExcludeProperty
protected boolean shouldExcludeProperty(PropertyDescriptor prop) throws SecurityException, NoSuchFieldException -
expandExpr
-
expandExpr
-
setExprStack
-
shouldExcludeProperty
-
add
protected boolean add(String name, Object value, Method method, boolean hasData) throws JSONException - Throws:
JSONException
-
map
- Throws:
JSONException
-
date
-
array
- Throws:
JSONException
-
array
- Throws:
JSONException
-
bool
protected void bool(boolean b) -
string
escape characters- Parameters:
obj
- the object to escape
-
add
-
add
protected void add(char c) -
unicode
protected void unicode(char c) Represent as unicode- Parameters:
c
- character to be encoded
-
setIgnoreHierarchy
public void setIgnoreHierarchy(boolean ignoreHierarchy) - Specified by:
setIgnoreHierarchy
in interfaceJSONWriter
-
setEnumAsBean
public 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())- Specified by:
setEnumAsBean
in interfaceJSONWriter
- Parameters:
enumAsBean
- true to serialize an enum as a bean instead of as a name=value pair (default=false)
-
setDateFormatter
- Specified by:
setDateFormatter
in interfaceJSONWriter
-
setCacheBeanInfo
public void setCacheBeanInfo(boolean cacheBeanInfo) - Specified by:
setCacheBeanInfo
in interfaceJSONWriter
-
setExcludeProxyProperties
public void setExcludeProxyProperties(boolean excludeProxyProperties) - Specified by:
setExcludeProxyProperties
in interfaceJSONWriter
-