Package groovy.json
Class DefaultJsonGenerator
java.lang.Object
groovy.json.DefaultJsonGenerator
- All Implemented Interfaces:
JsonGenerator
public class DefaultJsonGenerator extends java.lang.Object implements JsonGenerator
A JsonGenerator that can be configured with various
JsonGenerator.Options
.
If the default options are sufficient consider using the static JsonOutput.toJson
methods.- Since:
- 2.5.0
- See Also:
JsonGenerator.Options.build()
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultJsonGenerator.ClosureConverter
A converter that handles converting a given type using a closure.Nested classes/interfaces inherited from interface groovy.json.JsonGenerator
JsonGenerator.Converter, JsonGenerator.Options
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<JsonGenerator.Converter>
converters
protected java.lang.String
dateFormat
protected java.util.Locale
dateLocale
protected boolean
disableUnicodeEscaping
protected java.util.Set<java.lang.String>
excludedFieldNames
protected java.util.Set<java.lang.Class<?>>
excludedFieldTypes
protected boolean
excludeNulls
protected java.util.TimeZone
timezone
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultJsonGenerator(JsonGenerator.Options options)
-
Method Summary
Modifier and Type Method Description protected JsonGenerator.Converter
findConverter(java.lang.Class<?> type)
Finds a converter that can handle the given type.protected java.util.Map<?,?>
getObjectProperties(java.lang.Object object)
boolean
isExcludingFieldsNamed(java.lang.String name)
Indicates whether this JsonGenerator is configured to exclude fields by the given name.boolean
isExcludingValues(java.lang.Object value)
Indicates whether this JsonGenerator is configured to exclude values of the given object (may benull
).protected boolean
shouldExcludeType(java.lang.Class<?> type)
Indicates whether the given type should be excluded from the generated output.java.lang.String
toJson(java.lang.Object object)
Converts an object to its JSON representation.protected void
writeArray(java.lang.Class<?> arrayClass, java.lang.Object array, CharBuf buffer)
Serializes array and writes it into specified buffer.protected void
writeCharSequence(java.lang.CharSequence seq, CharBuf buffer)
Serializes any char sequence and writes it into specified buffer.protected void
writeDate(java.util.Date date, CharBuf buffer)
Serializes date and writes it into specified buffer.protected void
writeIterator(java.util.Iterator<?> iterator, CharBuf buffer)
Serializes iterator and writes it into specified buffer.protected void
writeMap(java.util.Map<?,?> map, CharBuf buffer)
Serializes map and writes it into specified buffer.protected void
writeMapEntry(java.lang.String key, java.lang.Object value, CharBuf buffer)
Serializes a map entry and writes it into specified buffer.protected void
writeNumber(java.lang.Class<?> numberClass, java.lang.Number value, CharBuf buffer)
Serializes Number value and writes it into specified buffer.protected void
writeObject(java.lang.Object object, CharBuf buffer)
protected void
writeObject(java.lang.String key, java.lang.Object object, CharBuf buffer)
Serializes object and writes it into specified buffer.protected void
writeRaw(java.lang.CharSequence seq, CharBuf buffer)
Serializes any char sequence and writes it into specified buffer without performing any manipulation of the given text.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
excludeNulls
protected final boolean excludeNulls -
disableUnicodeEscaping
protected final boolean disableUnicodeEscaping -
dateFormat
protected final java.lang.String dateFormat -
dateLocale
protected final java.util.Locale dateLocale -
timezone
protected final java.util.TimeZone timezone -
converters
-
excludedFieldNames
protected final java.util.Set<java.lang.String> excludedFieldNames -
excludedFieldTypes
protected final java.util.Set<java.lang.Class<?>> excludedFieldTypes
-
-
Constructor Details
-
DefaultJsonGenerator
-
-
Method Details
-
toJson
public java.lang.String toJson(java.lang.Object object)Converts an object to its JSON representation.- Specified by:
toJson
in interfaceJsonGenerator
- Parameters:
object
- to convert to JSON- Returns:
- JSON
-
isExcludingFieldsNamed
public boolean isExcludingFieldsNamed(java.lang.String name)Indicates whether this JsonGenerator is configured to exclude fields by the given name.- Specified by:
isExcludingFieldsNamed
in interfaceJsonGenerator
- Parameters:
name
- of the field- Returns:
- true if that field is being excluded, else false
-
isExcludingValues
public boolean isExcludingValues(java.lang.Object value)Indicates whether this JsonGenerator is configured to exclude values of the given object (may benull
).- Specified by:
isExcludingValues
in interfaceJsonGenerator
- Parameters:
value
- an instance of an object- Returns:
- true if values like this are being excluded, else false
-
writeNumber
Serializes Number value and writes it into specified buffer. -
writeObject
-
writeObject
Serializes object and writes it into specified buffer. -
getObjectProperties
protected java.util.Map<?,?> getObjectProperties(java.lang.Object object) -
writeCharSequence
Serializes any char sequence and writes it into specified buffer. -
writeRaw
Serializes any char sequence and writes it into specified buffer without performing any manipulation of the given text. -
writeDate
Serializes date and writes it into specified buffer. -
writeArray
Serializes array and writes it into specified buffer. -
writeMap
Serializes map and writes it into specified buffer. -
writeMapEntry
Serializes a map entry and writes it into specified buffer. -
writeIterator
Serializes iterator and writes it into specified buffer. -
findConverter
Finds a converter that can handle the given type. The first converter that reports it can handle the type is returned, based on the order in which the converters were specified. Anull
value will be returned if no suitable converter can be found for the given type.- Parameters:
type
- that this converter can handle- Returns:
- first converter that can handle the given type; else
null
if no compatible converters are found for the given type.
-
shouldExcludeType
protected boolean shouldExcludeType(java.lang.Class<?> type)Indicates whether the given type should be excluded from the generated output.- Parameters:
type
- the type to check- Returns:
true
if the given type should not be output, elsefalse
-