public class DefaultJsonGenerator extends java.lang.Object implements JsonGenerator
JsonGenerator.Options
.
If the default options are sufficient consider using the static JsonOutput.toJson
methods.JsonGenerator.Options.build()
Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultJsonGenerator.ClosureConverter
A converter that handles converting a given type using a closure.
|
JsonGenerator.Converter, JsonGenerator.Options
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
protected |
DefaultJsonGenerator(JsonGenerator.Options options) |
Modifier and Type | Method and 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 be
null ). |
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.
|
protected final boolean excludeNulls
protected final boolean disableUnicodeEscaping
protected final java.lang.String dateFormat
protected final java.util.Locale dateLocale
protected final java.util.TimeZone timezone
protected final java.util.Set<JsonGenerator.Converter> converters
protected final java.util.Set<java.lang.String> excludedFieldNames
protected final java.util.Set<java.lang.Class<?>> excludedFieldTypes
protected DefaultJsonGenerator(JsonGenerator.Options options)
public java.lang.String toJson(java.lang.Object object)
toJson
in interface JsonGenerator
object
- to convert to JSONpublic boolean isExcludingFieldsNamed(java.lang.String name)
isExcludingFieldsNamed
in interface JsonGenerator
name
- of the fieldpublic boolean isExcludingValues(java.lang.Object value)
null
).isExcludingValues
in interface JsonGenerator
value
- an instance of an objectprotected void writeNumber(java.lang.Class<?> numberClass, java.lang.Number value, CharBuf buffer)
protected void writeObject(java.lang.Object object, CharBuf buffer)
protected void writeObject(java.lang.String key, java.lang.Object object, CharBuf buffer)
protected java.util.Map<?,?> getObjectProperties(java.lang.Object object)
protected void writeCharSequence(java.lang.CharSequence seq, CharBuf buffer)
protected void writeRaw(java.lang.CharSequence seq, CharBuf buffer)
protected void writeDate(java.util.Date date, CharBuf buffer)
protected void writeArray(java.lang.Class<?> arrayClass, java.lang.Object array, CharBuf buffer)
protected void writeMap(java.util.Map<?,?> map, CharBuf buffer)
protected void writeMapEntry(java.lang.String key, java.lang.Object value, CharBuf buffer)
protected void writeIterator(java.util.Iterator<?> iterator, CharBuf buffer)
protected JsonGenerator.Converter findConverter(java.lang.Class<?> type)
null
value will be returned
if no suitable converter can be found for the given type.type
- that this converter can handlenull
if no compatible converters are found for the given type.protected boolean shouldExcludeType(java.lang.Class<?> type)
type
- the type to checktrue
if the given type should not be output, else false