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 SummaryNested Classes
- 
Field SummaryFields inherited from interface org.apache.struts2.json.JSONWriterENUM_AS_BEAN_DEFAULT
- 
Constructor SummaryConstructors
- 
Method SummaryModifier 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- 
DefaultJSONWriterpublic DefaultJSONWriter()
 
- 
- 
Method Details- 
setExcludeProxyProperties
- 
write- Specified by:
- writein interface- JSONWriter
- Parameters:
- object- Object to be serialized into JSON
- Returns:
- JSON string for object
- Throws:
- JSONException- in case of error during serialize
 
- 
writepublic String write(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties) throws JSONException - Specified by:
- writein interface- JSONWriter
- Parameters:
- object- Object to be serialized into JSON
- excludeProperties- Patterns matching properties to ignore
- includeProperties- Patterns matching properties to include
- excludeNullProperties- enable/disable excluding of null properties
- Returns:
- JSON string for object
- Throws:
- JSONException- in case of error during serialize
 
- 
valueDetect cyclic references- Parameters:
- object- Object to be serialized into JSON
- method- method
- Throws:
- JSONException- in case of error during serialize
 
- 
processSerialize object into json- Parameters:
- object- Object to be serialized into JSON
- method- method
- Throws:
- JSONException- in case of error during serialize
 
- 
processCustomSerialize custom object into json- Parameters:
- object- object
- method- method
- Throws:
- JSONException- in case of error during serialize
 
- 
beanInstrospect bean and serialize its properties- Parameters:
- object- object
- Throws:
- JSONException- in case of error during serialize
 
- 
getBeanInfoIgnoreHierarchy- Throws:
- IntrospectionException
 
- 
getBeanInfo- Throws:
- IntrospectionException
 
- 
getBridgedValueprotected Object getBridgedValue(Method baseAccessor, Object value) throws InstantiationException, IllegalAccessException 
- 
findBaseAccessor
- 
enumerationInstrospect 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
 
- 
shouldExcludePropertyprotected boolean shouldExcludeProperty(PropertyDescriptor prop) throws SecurityException, NoSuchFieldException 
- 
expandExpr
- 
expandExpr
- 
setExprStack
- 
shouldExcludeProperty
- 
addprotected boolean add(String name, Object value, Method method, boolean hasData) throws JSONException - Throws:
- JSONException
 
- 
map- Throws:
- JSONException
 
- 
date
- 
array- Throws:
- JSONException
 
- 
array- Throws:
- JSONException
 
- 
boolprotected void bool(boolean b) 
- 
stringescape characters- Parameters:
- obj- the object to escape
 
- 
add
- 
addprotected void add(char c) 
- 
unicodeprotected void unicode(char c) Represent as unicode- Parameters:
- c- character to be encoded
 
- 
setIgnoreHierarchypublic void setIgnoreHierarchy(boolean ignoreHierarchy) - Specified by:
- setIgnoreHierarchyin interface- JSONWriter
 
- 
setEnumAsBeanpublic 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 interface- JSONWriter
- Parameters:
- enumAsBean- true to serialize an enum as a bean instead of as a name=value pair (default=false)
 
- 
setDateFormatter- Specified by:
- setDateFormatterin interface- JSONWriter
 
- 
setCacheBeanInfopublic void setCacheBeanInfo(boolean cacheBeanInfo) - Specified by:
- setCacheBeanInfoin interface- JSONWriter
 
- 
setExcludeProxyPropertiespublic void setExcludeProxyProperties(boolean excludeProxyProperties) - Specified by:
- setExcludeProxyPropertiesin interface- JSONWriter
 
 
-