public class DefaultJsonGenerator extends 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 Set<JsonGenerator.Converter> |
converters |
protected String |
dateFormat |
protected Locale |
dateLocale |
protected boolean |
disableUnicodeEscaping |
protected Set<String> |
excludedFieldNames |
protected Set<Class<?>> |
excludedFieldTypes |
protected boolean |
excludeNulls |
protected TimeZone |
timezone |
Modifier | Constructor and Description |
---|---|
protected |
DefaultJsonGenerator(JsonGenerator.Options options) |
Modifier and Type | Method and Description |
---|---|
protected JsonGenerator.Converter |
findConverter(Class<?> type)
Finds a converter that can handle the given type.
|
protected Map<?,?> |
getObjectProperties(Object object) |
boolean |
isExcludingFieldsNamed(String name)
Indicates whether this JsonGenerator is configured to exclude fields by
the given name.
|
boolean |
isExcludingValues(Object value)
Indicates whether this JsonGenerator is configured to exclude values
of the given object (may be
null ). |
protected boolean |
shouldExcludeType(Class<?> type)
Indicates whether the given type should be excluded from the generated output.
|
String |
toJson(Object object)
Converts an object to its JSON representation.
|
protected void |
writeArray(Class<?> arrayClass,
Object array,
CharBuf buffer)
Serializes array and writes it into specified buffer.
|
protected void |
writeCharSequence(CharSequence seq,
CharBuf buffer)
Serializes any char sequence and writes it into specified buffer.
|
protected void |
writeDate(Date date,
CharBuf buffer)
Serializes date and writes it into specified buffer.
|
protected void |
writeIterator(Iterator<?> iterator,
CharBuf buffer)
Serializes iterator and writes it into specified buffer.
|
protected void |
writeMap(Map<?,?> map,
CharBuf buffer)
Serializes map and writes it into specified buffer.
|
protected void |
writeMapEntry(String key,
Object value,
CharBuf buffer)
Serializes a map entry and writes it into specified buffer.
|
protected void |
writeNumber(Class<?> numberClass,
Number value,
CharBuf buffer)
Serializes Number value and writes it into specified buffer.
|
protected void |
writeObject(Object object,
CharBuf buffer) |
protected void |
writeObject(String key,
Object object,
CharBuf buffer)
Serializes object and writes it into specified buffer.
|
protected void |
writeRaw(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 String dateFormat
protected final Locale dateLocale
protected final TimeZone timezone
protected final Set<JsonGenerator.Converter> converters
protected DefaultJsonGenerator(JsonGenerator.Options options)
public String toJson(Object object)
toJson
in interface JsonGenerator
object
- to convert to JSONpublic boolean isExcludingFieldsNamed(String name)
isExcludingFieldsNamed
in interface JsonGenerator
name
- of the fieldpublic boolean isExcludingValues(Object value)
null
).isExcludingValues
in interface JsonGenerator
value
- an instance of an objectprotected void writeNumber(Class<?> numberClass, Number value, CharBuf buffer)
protected void writeObject(String key, Object object, CharBuf buffer)
protected void writeCharSequence(CharSequence seq, CharBuf buffer)
protected void writeRaw(CharSequence seq, CharBuf buffer)
protected void writeDate(Date date, CharBuf buffer)
protected void writeArray(Class<?> arrayClass, Object array, CharBuf buffer)
protected void writeMap(Map<?,?> map, CharBuf buffer)
protected void writeMapEntry(String key, Object value, CharBuf buffer)
protected void writeIterator(Iterator<?> iterator, CharBuf buffer)
protected JsonGenerator.Converter findConverter(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(Class<?> type)
type
- the type to checktrue
if the given type should not be output, else false