org.apache.struts2.json

## Class DefaultJSONWriter

- java.lang.Object
- - org.apache.struts2.json.DefaultJSONWriter

- All Implemented Interfaces:
    JSONWriter

      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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `DefaultJSONWriter.JSONAnnotationFinder`

  - ### Field Summary

    - ### Fields inherited from interface org.apache.struts2.json.JSONWriter

      `ENUM_AS_BEAN_DEFAULT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultJSONWriter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultJSONWriter

          public DefaultJSONWriter()

  - ### Method Detail

    - #### setExcludeProxyProperties

          public void setExcludeProxyProperties(String excludeProxyProperties)

    - #### write

          public String write(Object object)
                       throws JSONException

      Specified by:
        `write` in interface `JSONWriter`
      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 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

    - #### value

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

      Detect cyclic references
      Parameters:
        `object` - Object to be serialized into JSON
        `method` - method
      Throws:
        `JSONException` - in case of error during serialize

    - #### process

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

      Serialize object into json
      Parameters:
        `object` - Object to be serialized into JSON
        `method` - method
      Throws:
        `JSONException` - in case of error during serialize

    - #### processCustom

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

      Serialize custom object into json
      Parameters:
        `object` - object
        `method` - method
      Throws:
        `JSONException` - in case of error during serialize

    - #### bean

          protected void bean(Object object)
                       throws JSONException

      Instrospect bean and serialize its properties
      Parameters:
        `object` - object
      Throws:
        `JSONException` - in case of error during serialize

    - #### 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
      Parameters:
        `enumeration` - the enum
      Throws:
        `JSONException` - in case of error during serialize

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

      Throws:
        `JSONException`

    - #### map

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

      Throws:
        `JSONException`

    - #### date

          protected void date(Date date,
                              Method method)

    - #### array

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

      Throws:
        `JSONException`

    - #### array

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

      Throws:
        `JSONException`

    - #### bool

          protected void bool(boolean b)

    - #### string

          protected void string(Object obj)

      escape characters
      Parameters:
        `obj` - the object to escape

    - #### add

          protected void add(Object obj)

    - #### 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 interface `JSONWriter`

    - #### 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 interface `JSONWriter`
      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)

      Specified by:
        `setDateFormatter` in interface `JSONWriter`

    - #### setCacheBeanInfo

          public void setCacheBeanInfo(boolean cacheBeanInfo)

      Specified by:
        `setCacheBeanInfo` in interface `JSONWriter`

    - #### setExcludeProxyProperties

          public void setExcludeProxyProperties(boolean excludeProxyProperties)

      Specified by:
        `setExcludeProxyProperties` in interface `JSONWriter`

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