Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.json
Class JSONWriter

    java.lang.Object
      org.apache.struts2.json.JSONWriter

    public class JSONWriter

extends Object

Serializes an object into JavaScript Object Notation (JSON). If cyclic references are detected they will be nulled out.

Nested Class Summary
`protected static class` | `JSONWriter.JSONAnnotationFinder`

Field Summary
`static boolean` | `ENUM_AS_BEAN_DEFAULT` By default, enums are serialised as name=value pairs

Constructor Summary
`JSONWriter()`

Method Summary
`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)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### ENUM_AS_BEAN_DEFAULT

    public static final boolean ENUM_AS_BEAN_DEFAULT

  By default, enums are serialised as name=value pairs

  See Also:
    Constant Field Values

Constructor Detail

### JSONWriter

    public JSONWriter()

Method Detail

### write

    public String write(Object object)
                 throws JSONException

  Parameters:
    `object` - Object to be serialized into JSON
  Returns:
    JSON string for object
  Throws:
    `JSONException`

### write

    public String write(Object object,
                        Collection<Pattern> excludeProperties,
                        Collection<Pattern> includeProperties,
                        boolean excludeNullProperties)
                 throws JSONException

  Parameters:
    `object` - Object to be serialized into JSON
  Returns:
    JSON string for object
  Throws:
    `JSONException`

### value

    protected void value(Object object,
                         Method method)
                  throws JSONException

  Detect cyclic references

  Throws:
    `JSONException`

### process

    protected void process(Object object,
                           Method method)
                    throws JSONException

  Serialize object into json

  Throws:
    `JSONException`

### processCustom

    protected void processCustom(Object object,
                                 Method method)
                          throws JSONException

  Serialize custom object into json

  Throws:
    `JSONException`

### bean

    protected void bean(Object object)
                 throws JSONException

  Instrospect bean and serialize its properties

  Throws:
    `JSONException`

### getBeanInfoIgnoreHierarchy

    protected BeanInfo getBeanInfoIgnoreHierarchy(Class<?> clazz)
                                           throws IntrospectionException

  Throws:
    `IntrospectionException`

### getBeanInfo

    protected BeanInfo getBeanInfo(Class<?> clazz)
                            throws IntrospectionException

  Throws:
    `IntrospectionException`

### getBridgedValue

    protected Object getBridgedValue(Method baseAccessor,
                                     Object value)
                              throws InstantiationException,
                                     IllegalAccessException

  Throws:
    `InstantiationException`
    `IllegalAccessException`

### findBaseAccessor

    protected Method findBaseAccessor(Class clazz,
                                      Method accessor)

### enumeration

    protected void enumeration(Enum enumeration)
                        throws JSONException

  Instrospect an Enum and serialize it as a name/value pair or as a bean including all its own properties

  Throws:
    `JSONException`

### shouldExcludeProperty

    protected boolean shouldExcludeProperty(PropertyDescriptor prop)
                                     throws SecurityException,
                                            NoSuchFieldException

  Throws:
    `SecurityException`
    `NoSuchFieldException`

### expandExpr

    protected String expandExpr(int i)

### expandExpr

    protected String expandExpr(String property)

### setExprStack

    protected String setExprStack(String expr)

### shouldExcludeProperty

    protected boolean shouldExcludeProperty(String expr)

### add

    protected boolean add(String name,
                          Object value,
                          Method method,
                          boolean hasData)
                   throws JSONException

  Add name/value pair to buffer

  Throws:
    `JSONException`

### map

    protected void map(Map map,
                       Method method)
                throws JSONException

  Add map to buffer

  Throws:
    `JSONException`

### date

    protected void date(Date date,
                        Method method)

  Add date to buffer

### array

    protected void array(Iterator it,
                         Method method)
                  throws JSONException

  Add array to buffer

  Throws:
    `JSONException`

### array

    protected void array(Object object,
                         Method method)
                  throws JSONException

  Add array to buffer

  Throws:
    `JSONException`

### bool

    protected void bool(boolean b)

  Add boolean to buffer

### string

    protected void string(Object obj)

  escape characters

### add

    protected void add(Object obj)

  Add object to buffer

### add

    protected void add(char c)

  Add char to buffer

### unicode

    protected void unicode(char c)

  Represent as unicode

  Parameters:
    `c` - character to be encoded

### setIgnoreHierarchy

    public void setIgnoreHierarchy(boolean ignoreHierarchy)

### 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())

  Parameters:
    `enumAsBean` - true to serialize an enum as a bean instead of as a name=value pair (default=false)

### setDateFormatter

    public void setDateFormatter(String defaultDateFormat)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000–2017 Apache Software Foundation. All rights reserved.