public class JSONUtil extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
JSONUtil.ClassVisitor
Realizes the visit(Class) method called by vistInterfaces for all
encountered classes/interfaces
|
Modifier and Type | Field and Description |
---|---|
static boolean |
CACHE_BEAN_INFO_DEFAULT |
static String |
REGEXP_PATTERN |
static String |
RFC3339_FORMAT |
static String |
WILDCARD_PATTERN |
Constructor and Description |
---|
JSONUtil() |
Modifier and Type | Method and Description |
---|---|
static Set<String> |
asSet(String commaDelim) |
static Object |
deserialize(Reader reader)
Deserializes a object from JSON
|
static Object |
deserialize(String json)
Deserializes a object from JSON
|
static boolean |
isGzipInRequest(javax.servlet.http.HttpServletRequest request) |
static Method[] |
listSMDMethods(Class clazz,
boolean ignoreInterfaces)
List visible methods carrying the
@SMDMethod annotation
|
static List<Pattern> |
processIncludePatterns(Set<String> includePatterns,
String type) |
String |
serialize(Object object,
boolean cacheBeanInfo)
Serializes an object into JSON.
|
String |
serialize(Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean ignoreHierarchy,
boolean excludeNullProperties)
Serializes an object into JSON, excluding any properties matching any of
the regular expressions in the given collection.
|
String |
serialize(Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean ignoreHierarchy,
boolean excludeNullProperties,
boolean cacheBeanInfo)
Serializes an object into JSON, excluding any properties matching any of
the regular expressions in the given collection.
|
String |
serialize(Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean ignoreHierarchy,
boolean enumAsBean,
boolean excludeNullProperties,
String defaultDateFormat)
Serializes an object into JSON, excluding any properties matching any of
the regular expressions in the given collection.
|
String |
serialize(Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean ignoreHierarchy,
boolean enumAsBean,
boolean excludeNullProperties,
String defaultDateFormat,
boolean cacheBeanInfo)
Serializes an object into JSON, excluding any properties matching any of
the regular expressions in the given collection.
|
void |
serialize(Writer writer,
Object object)
Serializes an object into JSON to the given writer.
|
void |
serialize(Writer writer,
Object object,
boolean cacheBeanInfo)
Serializes an object into JSON to the given writer.
|
void |
serialize(Writer writer,
Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean excludeNullProperties)
Serializes an object into JSON to the given writer, excluding any
properties matching any of the regular expressions in the given
collection.
|
void |
serialize(Writer writer,
Object object,
Collection<Pattern> excludeProperties,
Collection<Pattern> includeProperties,
boolean excludeNullProperties,
boolean cacheBeanInfo)
Serializes an object into JSON to the given writer, excluding any
properties matching any of the regular expressions in the given
collection.
|
void |
setContainer(Container container) |
void |
setWriter(JSONWriter writer) |
static boolean |
visitInterfaces(Class aClass,
JSONUtil.ClassVisitor visitor)
Visit all the interfaces realized by the specified object, its
superclasses and its interfaces
Visitation is performed in the following order: aClass aClass' interfaces the interface's superclasses (interfaces) aClass' superclass superclass' interfaces superclass' interface's superclasses (interfaces) super-superclass and so on The Object base class is base excluded. |
static void |
writeJSONToResponse(SerializationParams serializationParams) |
public static final String RFC3339_FORMAT
public static final boolean CACHE_BEAN_INFO_DEFAULT
public static final String REGEXP_PATTERN
public static final String WILDCARD_PATTERN
public void setWriter(JSONWriter writer)
public void setContainer(Container container)
public String serialize(Object object, boolean cacheBeanInfo) throws JSONException
object
- to be serializedcacheBeanInfo
- Specifies whether to cache bean info in the JSONWriterJSONException
- in case of error during serializepublic String serialize(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean ignoreHierarchy, boolean excludeNullProperties) throws JSONException
object
- to be serializedexcludeProperties
- Patterns matching properties to excludeincludeProperties
- Patterns matching properties to includeignoreHierarchy
- whether to ignore properties defined on base classes of the
root objectexcludeNullProperties
- enable/disable excluding of null propertiesJSONException
- in case of error during serializepublic String serialize(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean ignoreHierarchy, boolean excludeNullProperties, boolean cacheBeanInfo) throws JSONException
object
- to be serializedexcludeProperties
- Patterns matching properties to excludeincludeProperties
- Patterns matching properties to includeignoreHierarchy
- whether to ignore properties defined on base classes of the
root objectexcludeNullProperties
- enable/disable excluding of null propertiescacheBeanInfo
- Specifies whether to cache bean info in the JSONWriterJSONException
- in case of error during serializepublic String serialize(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean ignoreHierarchy, boolean enumAsBean, boolean excludeNullProperties, String defaultDateFormat) throws JSONException
object
- to be serializedexcludeProperties
- Patterns matching properties to excludeincludeProperties
- Patterns matching properties to includeignoreHierarchy
- whether to ignore properties defined on base classes of the
root objectenumAsBean
- whether to serialized enums a Bean or name=value pairexcludeNullProperties
- enable/disable excluding of null propertiesdefaultDateFormat
- date format used to serialize datesJSONException
- in case of error during serializepublic String serialize(Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean ignoreHierarchy, boolean enumAsBean, boolean excludeNullProperties, String defaultDateFormat, boolean cacheBeanInfo) throws JSONException
object
- to be serializedexcludeProperties
- Patterns matching properties to excludeincludeProperties
- Patterns matching properties to includeignoreHierarchy
- whether to ignore properties defined on base classes of the
root objectenumAsBean
- whether to serialized enums a Bean or name=value pairexcludeNullProperties
- enable/disable excluding of null propertiesdefaultDateFormat
- date format used to serialize datescacheBeanInfo
- Specifies whether to cache bean info in the JSONWriterJSONException
- in case of error during serializepublic void serialize(Writer writer, Object object) throws IOException, JSONException
writer
- Writer to serialize the object toobject
- object to be serializedIOException
- in case of IO errorsJSONException
- in case of error during serializepublic void serialize(Writer writer, Object object, boolean cacheBeanInfo) throws IOException, JSONException
writer
- Writer to serialize the object toobject
- object to be serializedcacheBeanInfo
- Specifies whether to cache bean info in the JSONWriterIOException
- in case of IO errorsJSONException
- in case of error during serializepublic void serialize(Writer writer, Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties) throws IOException, JSONException
writer
- Writer to serialize the object toobject
- object to be serializedexcludeProperties
- Patterns matching properties to ignoreincludeProperties
- Patterns matching properties to includeexcludeNullProperties
- enable/disable excluding of null propertiesIOException
- in case of IO errorsJSONException
- in case of error during serializepublic void serialize(Writer writer, Object object, Collection<Pattern> excludeProperties, Collection<Pattern> includeProperties, boolean excludeNullProperties, boolean cacheBeanInfo) throws IOException, JSONException
writer
- Writer to serialize the object toobject
- object to be serializedexcludeProperties
- Patterns matching properties to ignoreincludeProperties
- Patterns matching properties to includeexcludeNullProperties
- enable/disable excluding of null propertiescacheBeanInfo
- Specifies whether to cache bean info in the JSONWriterIOException
- in case of IO errorsJSONException
- in case of error during serializepublic static Object deserialize(String json) throws JSONException
json
- string in JSONJSONException
- in case of error during serializepublic static Object deserialize(Reader reader) throws JSONException
reader
- Reader to read a JSON string fromJSONException
- when IOException happenspublic static void writeJSONToResponse(SerializationParams serializationParams) throws IOException
IOException
public static Method[] listSMDMethods(Class clazz, boolean ignoreInterfaces)
clazz
- classignoreInterfaces
- if true, only the methods of the class are examined. If false,
annotations on every interfaces' methods are examined.public static boolean visitInterfaces(Class aClass, JSONUtil.ClassVisitor visitor)
aClass
- the class to start recursing upwards fromvisitor
- this vistor is called for each class/interface encounteredpublic static boolean isGzipInRequest(javax.servlet.http.HttpServletRequest request)
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.