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 voidadd(char c) protected voidprotected booleanprotected voidprotected voidprotected voidInstrospect bean and serialize its propertiesprotected voidbool(boolean b) protected voidprotected voidenumeration(Enum enumeration) Instrospect an Enum and serialize it as a name/value pair or as a bean including all its own propertiesprotected StringexpandExpr(int i) protected StringexpandExpr(String property) protected MethodfindBaseAccessor(Class clazz, Method accessor) protected BeanInfogetBeanInfo(Class<?> clazz) protected BeanInfogetBeanInfoIgnoreHierarchy(Class<?> clazz) protected ObjectgetBridgedValue(Method baseAccessor, Object value) protected voidprotected voidSerialize object into jsonprotected voidprocessCustom(Object object, Method method) Serialize custom object into jsonvoidsetCacheBeanInfo(boolean cacheBeanInfo) voidsetDateFormatter(String defaultDateFormat) voidsetEnumAsBean(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())voidsetExcludeProxyProperties(boolean excludeProxyProperties) voidsetExcludeProxyProperties(String excludeProxyProperties) protected StringsetExprStack(String expr) voidsetIgnoreHierarchy(boolean ignoreHierarchy) protected booleanprotected booleanshouldExcludeProperty(String expr) protected voidescape charactersprotected voidunicode(char c) Represent as unicodeprotected voidDetect cyclic referenceswrite(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties)
-
Constructor Details
-
DefaultJSONWriter
public DefaultJSONWriter()
-
-
Method Details
-
setExcludeProxyProperties
-
write
- Specified by:
writein 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:
writein 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:
setIgnoreHierarchyin 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:
setEnumAsBeanin interfaceJSONWriter- Parameters:
enumAsBean- true to serialize an enum as a bean instead of as a name=value pair (default=false)
-
setDateFormatter
- Specified by:
setDateFormatterin interfaceJSONWriter
-
setCacheBeanInfo
public void setCacheBeanInfo(boolean cacheBeanInfo) - Specified by:
setCacheBeanInfoin interfaceJSONWriter
-
setExcludeProxyProperties
public void setExcludeProxyProperties(boolean excludeProxyProperties) - Specified by:
setExcludeProxyPropertiesin interfaceJSONWriter
-