public abstract class JSONWriter
extends java.lang.Object
implements java.io.Closeable
JSONWriter supports multiple output destinations including strings, byte arrays, streams, and writers. It also supports different character encodings such as UTF-8, UTF-16, and others.
Example usage:
// Writing to a string
try (JSONWriter writer = JSONWriter.of()) {
writer.writeAny(object);
String json = writer.toString();
}
// Writing to a stream
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
JSONWriter writer = JSONWriter.of(out, StandardCharsets.UTF_8)) {
writer.writeAny(object);
byte[] jsonBytes = out.toByteArray();
}
// Writing with specific features
try (JSONWriter writer = JSONWriter.of(JSONWriter.Feature.PrettyFormat)) {
writer.writeAny(object);
String prettyJson = writer.toString();
}
JSONWriter instances are not thread-safe and should not be shared between multiple threads. Each thread should create its own JSONWriter instance or use the factory methods to create new instances as needed.
JSONWriter.Context,
JSONWriter.Feature| Modifier and Type | Class and Description |
|---|---|
static class |
JSONWriter.Context
Context holds the configuration and state information for JSON writing operations.
|
static class |
JSONWriter.Feature
Feature is used to control the behavior of JSON writing and serialization in FASTJSON2.
|
static class |
JSONWriter.Path
Path represents a JSON pointer path used for reference detection during serialization.
|
| Modifier | Constructor and Description |
|---|---|
protected |
JSONWriter(JSONWriter.Context context,
SymbolTable symbolTable,
boolean jsonb,
java.nio.charset.Charset charset) |
| Modifier and Type | Method and Description |
|---|---|
void |
addManagerReference(java.lang.Object object)
Adds a manager reference for the specified object.
|
void |
checkAndWriteTypeName(java.lang.Object object,
java.lang.Class fieldClass)
Checks if type name should be written for the given object and writes it if necessary.
|
abstract void |
close()
Closes this JSONWriter and releases any resources associated with it.
|
void |
config(JSONWriter.Feature... features)
Configures features for this JSONWriter.
|
void |
config(JSONWriter.Feature feature,
boolean state)
Configures a specific feature for this JSONWriter.
|
boolean |
containsReference(java.lang.Object value)
Checks if the specified object is contained in the reference map.
|
void |
decrementIdent()
Deprecated.
This method is deprecated and will be removed in a future version
|
abstract void |
endArray()
Ends the current JSON array.
|
abstract void |
endObject()
Ends writing a JSON object.
|
abstract java.lang.Object |
ensureCapacity(int minCapacity)
Ensures that the internal buffer has at least the specified minimum capacity.
|
abstract int |
flushTo(java.io.OutputStream to)
Flushes the content of this JSONWriter to the specified OutputStream.
|
abstract int |
flushTo(java.io.OutputStream out,
java.nio.charset.Charset charset)
Flushes the content of this JSONWriter to the specified OutputStream using the specified charset.
|
void |
flushTo(java.io.Writer to)
Flushes the content of this JSONWriter to the specified Writer.
|
java.lang.Object |
getAttachment()
Gets the attachment object associated with this JSONWriter.
|
abstract byte[] |
getBytes()
Gets the content of the output buffer as a byte array.
|
abstract byte[] |
getBytes(java.nio.charset.Charset charset)
Gets the content of the output buffer as a byte array using the specified charset.
|
java.nio.charset.Charset |
getCharset()
Gets the charset used by this JSONWriter.
|
JSONWriter.Context |
getContext()
Gets the context used by this JSONWriter.
|
long |
getFeatures()
Gets the features bitmask.
|
long |
getFeatures(long features)
Gets the combined features bitmask including the specified additional features.
|
ObjectWriter |
getObjectWriter(java.lang.Class objectClass)
Gets the ObjectWriter for the specified object class.
|
ObjectWriter |
getObjectWriter(java.lang.Class objectClass,
java.lang.String format)
Gets the ObjectWriter for the specified object class with a specific format.
|
ObjectWriter |
getObjectWriter(java.lang.reflect.Type objectType,
java.lang.Class objectClass)
Gets the ObjectWriter for the specified object type and class.
|
int |
getOffset()
Gets the current offset in the internal buffer.
|
java.lang.String |
getPath()
If ReferenceDetection has been set, returns the path of the current object, otherwise returns null
|
java.lang.String |
getPath(java.lang.Object value)
Gets the path of the specified object in the reference map.
|
SymbolTable |
getSymbolTable()
Gets the symbol table used by this JSONWriter.
|
boolean |
hasFilter()
Checks if any filter is configured for this JSONWriter.
|
boolean |
hasFilter(boolean containsNoneFieldGetter)
Checks if any filter is configured for this JSONWriter or if the IgnoreNonFieldGetter feature
should be applied based on the containsNoneFieldGetter parameter.
|
boolean |
hasFilter(long feature)
Checks if any filter or the specified feature is configured for this JSONWriter.
|
protected static java.lang.IllegalArgumentException |
illegalYear(int year) |
void |
incrementIndent()
Deprecated.
This method is deprecated and will be removed in a future version
|
boolean |
isBeanToArray()
Checks if the BeanToArray feature is enabled.
|
boolean |
isEnabled(JSONWriter.Feature feature)
Checks if the specified feature is enabled.
|
boolean |
isEnabled(long feature)
Checks if the specified feature is enabled.
|
boolean |
isIgnoreErrorGetter()
Checks if the IgnoreErrorGetter feature is enabled.
|
boolean |
isIgnoreNoneSerializable()
Checks if the IgnoreNoneSerializable feature is enabled.
|
boolean |
isIgnoreNoneSerializable(java.lang.Object object)
Checks if the IgnoreNoneSerializable feature is enabled for the specified object.
|
boolean |
isRefDetect()
Checks if the ReferenceDetection feature is enabled.
|
boolean |
isRefDetect(java.lang.Object object)
Checks if the ReferenceDetection feature is enabled for the specified object.
|
boolean |
isUseSingleQuotes()
Checks if single quotes are being used for this JSONWriter.
|
boolean |
isUTF16()
Checks if this JSONWriter is using UTF-16 encoding.
|
boolean |
isUTF8()
Checks if this JSONWriter is using UTF-8 encoding.
|
protected static boolean |
isWriteAsString(java.math.BigDecimal value,
long features) |
protected static boolean |
isWriteAsString(java.math.BigInteger value,
long features) |
static boolean |
isWriteAsString(long value,
long features) |
boolean |
isWriteMapTypeInfo(java.lang.Object object,
java.lang.Class fieldClass,
long features)
Checks if map type information should be written for the specified object, field class, and features.
|
boolean |
isWriteNulls()
Checks if the WriteNulls feature is enabled.
|
boolean |
isWriteTypeInfo(java.lang.Object object)
Checks if type information should be written for the specified object.
|
boolean |
isWriteTypeInfo(java.lang.Object object,
java.lang.Class fieldClass)
Checks if type information should be written for the specified object and field class.
|
boolean |
isWriteTypeInfo(java.lang.Object object,
java.lang.Class fieldClass,
long features)
Checks if type information should be written for the specified object, field class, and features.
|
boolean |
isWriteTypeInfo(java.lang.Object object,
long features)
Checks if type information should be written for the specified object and features.
|
boolean |
isWriteTypeInfo(java.lang.Object object,
java.lang.reflect.Type fieldType)
Checks if type information should be written for the specified object and field type.
|
boolean |
isWriteTypeInfo(java.lang.Object object,
java.lang.reflect.Type fieldType,
long features)
Checks if type information should be written for the specified object, field type, and features.
|
private static boolean |
isWriteTypeInfoGenericArray(java.lang.reflect.GenericArrayType fieldType,
java.lang.Class objectClass) |
int |
level()
Gets the current nesting level of this JSONWriter.
|
protected int |
newCapacity(int minCapacity,
int oldCapacity)
Calculates the new capacity for the internal buffer based on the minimum required capacity.
|
static JSONWriter |
of()
Creates a new JSONWriter with default configuration.
|
static JSONWriter |
of(JSONWriter.Context context)
Creates a new JSONWriter with the specified context.
|
static JSONWriter |
of(JSONWriter.Feature... features)
Creates a new JSONWriter with the specified features.
|
static JSONWriter |
of(ObjectWriterProvider provider,
JSONWriter.Feature... features)
Creates a new JSONWriter with the specified object writer provider and features.
|
static JSONWriter |
ofJSONB()
Creates a new JSONWriter instance for JSONB (binary JSON) format with default context.
|
static JSONWriter |
ofJSONB(JSONWriter.Context context)
Creates a new JSONWriter instance for JSONB (binary JSON) format with the specified context.
|
static JSONWriter |
ofJSONB(JSONWriter.Context context,
SymbolTable symbolTable)
Creates a new JSONWriter instance for JSONB (binary JSON) format with the specified context and symbol table.
|
static JSONWriter |
ofJSONB(JSONWriter.Feature... features)
Creates a new JSONWriter instance for JSONB (binary JSON) format with the specified features.
|
static JSONWriter |
ofJSONB(SymbolTable symbolTable)
Creates a new JSONWriter instance for JSONB (binary JSON) format with the specified symbol table.
|
static JSONWriter |
ofPretty()
Creates a new JSONWriter instance with pretty formatting enabled.
|
static JSONWriter |
ofPretty(JSONWriter writer)
Enables pretty formatting on an existing JSONWriter instance.
|
static JSONWriter |
ofUTF16(JSONWriter.Feature... features)
Creates a new JSONWriter instance using UTF-16 encoding with the specified features.
|
static JSONWriter |
ofUTF8()
Creates a new JSONWriter instance using UTF-8 encoding with default context.
|
static JSONWriter |
ofUTF8(JSONWriter.Context context)
Creates a new JSONWriter instance using UTF-8 encoding with the specified context.
|
static JSONWriter |
ofUTF8(JSONWriter.Feature... features)
Creates a new JSONWriter instance using UTF-8 encoding with the specified features.
|
protected void |
overflowLevel()
Throws a JSONException indicating that the nesting level has exceeded the maximum allowed level.
|
void |
popPath(java.lang.Object object)
Removes the path for the specified object.
|
void |
popPath0(java.lang.Object object)
Removes the path for the specified object without reference detection.
|
void |
println()
Deprecated.
This method is deprecated and will be removed in a future version
|
boolean |
removeReference(java.lang.Object value)
Removes the reference to the specified object.
|
void |
setAttachment(java.lang.Object attachment)
Sets the attachment object for this JSONWriter.
|
void |
setOffset(int offset)
Sets the offset in the internal buffer.
|
java.lang.String |
setPath(FieldWriter fieldWriter,
java.lang.Object object)
Sets the path for the specified object using the provided field writer.
|
java.lang.String |
setPath(int index,
java.lang.Object object)
Sets the path for the specified object at the given index.
|
java.lang.String |
setPath(java.lang.String name,
java.lang.Object object)
Sets the path for the specified object with the given name.
|
java.lang.String |
setPath0(FieldWriter fieldWriter,
java.lang.Object object)
Sets the path for the specified object using the provided field writer without reference detection.
|
java.lang.String |
setPath0(int index,
java.lang.Object object)
Sets the path for the specified object at the given index without reference detection.
|
void |
setRootObject(java.lang.Object rootObject)
Sets the root object for this JSONWriter.
|
abstract int |
size()
Gets the current size of the output buffer.
|
abstract void |
startArray()
Starts writing a JSON array.
|
void |
startArray(int size)
Starts writing a JSON array with a specified initial capacity.
|
void |
startArray(java.lang.Object array,
int size)
Starts writing a JSON array with the specified array and size.
|
void |
startArray0()
Starts writing a JSON array with zero expected elements.
|
void |
startArray1()
Starts writing a JSON array with one expected element.
|
void |
startArray10()
Starts writing a JSON array with ten expected elements.
|
void |
startArray11()
Starts writing a JSON array with eleven expected elements.
|
void |
startArray12()
Starts writing a JSON array with twelve expected elements.
|
void |
startArray13()
Starts writing a JSON array with thirteen expected elements.
|
void |
startArray14()
Starts writing a JSON array with fourteen expected elements.
|
void |
startArray15()
Starts writing a JSON array with fifteen expected elements.
|
void |
startArray2()
Starts writing a JSON array with two expected elements.
|
void |
startArray3()
Starts writing a JSON array with three expected elements.
|
void |
startArray4()
Starts writing a JSON array with four expected elements.
|
void |
startArray5()
Starts writing a JSON array with five expected elements.
|
void |
startArray6()
Starts writing a JSON array with six expected elements.
|
void |
startArray7()
Starts writing a JSON array with seven expected elements.
|
void |
startArray8()
Starts writing a JSON array with eight expected elements.
|
void |
startArray9()
Starts writing a JSON array with nine expected elements.
|
abstract void |
startObject()
Starts writing a JSON object.
|
void |
write(JSONObject map)
Writes a JSONObject as a JSON object.
|
abstract void |
write(java.util.List array)
Writes a list as a JSON array.
|
void |
write(java.util.Map<?,?> map)
Writes a Map as a JSON object.
|
protected abstract void |
write0(char ch)
Writes a character to the output.
|
void |
writeAny(java.lang.Object value)
Writes any object using the appropriate writer based on its runtime type.
|
void |
writeArrayNull()
Writes a null array value using the current context features.
|
void |
writeArrayNull(long features)
Writes a null array value using the specified features.
|
void |
writeAs(java.lang.Object value,
java.lang.Class type)
Writes an object as if it were of the specified type.
|
abstract void |
writeBase64(byte[] bytes)
Writes a byte array as Base64-encoded string.
|
void |
writeBigInt(java.math.BigInteger value)
Writes a BigInteger value using default features.
|
abstract void |
writeBigInt(java.math.BigInteger value,
long features)
Writes a BigInteger value using the specified features.
|
void |
writeBinary(byte[] bytes)
Writes a byte array as either Base64-encoded string or as an array of integers,
depending on the WriteByteArrayAsBase64 feature.
|
abstract void |
writeBool(boolean value)
Writes a boolean value.
|
void |
writeBool(boolean[] value)
Writes a boolean array as boolean values.
|
void |
writeBooleanNull()
Writes a null boolean value using the current context features.
|
abstract void |
writeChar(char ch)
Writes a character without any escaping or formatting.
|
abstract void |
writeColon()
Writes a colon separator.
|
abstract void |
writeComma()
Writes a comma separator.
|
abstract void |
writeDateTime14(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
Writes a date-time value in 14-character format (yyyyMMddHHmmss).
|
abstract void |
writeDateTime19(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
Writes a date-time value in 19-character format (yyyy-MM-dd HH:mm:ss).
|
abstract void |
writeDateTimeISO8601(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int millis,
int offsetSeconds,
boolean timeZone)
Writes a date-time value in ISO8601 format.
|
abstract void |
writeDateYYYMMDD10(int year,
int month,
int dayOfMonth)
Writes a date in 10-character format (yyyy-MM-dd).
|
abstract void |
writeDateYYYMMDD8(int year,
int month,
int dayOfMonth)
Writes a date in 8-character format (yyyyMMdd).
|
void |
writeDecimal(java.math.BigDecimal value)
Writes a BigDecimal value using default features and no specific format.
|
void |
writeDecimal(java.math.BigDecimal value,
long features)
Writes a BigDecimal value using the specified features and no specific format.
|
abstract void |
writeDecimal(java.math.BigDecimal value,
long features,
java.text.DecimalFormat format)
Writes a BigDecimal value using the specified features and decimal format.
|
void |
writeDecimalNull()
Writes a null decimal value using the current context features.
|
void |
writeDecimalNull(long features)
Writes a null decimal value using the specified features.
|
abstract void |
writeDouble(double value)
Writes a double value.
|
abstract void |
writeDouble(double[] value)
Writes a double array as floating-point numbers.
|
void |
writeDouble(double[] value,
java.text.DecimalFormat format)
Writes a double array as floating-point numbers with the specified decimal format.
|
void |
writeDouble(double value,
java.text.DecimalFormat format)
Writes a double value with the specified decimal format.
|
void |
writeDoubleArray(double value0,
double value1)
Writes a double array with two elements.
|
void |
writeEnum(java.lang.Enum e)
Writes an Enum value.
|
abstract void |
writeFloat(float value)
Writes a float value.
|
void |
writeFloat(java.lang.Float value)
Writes a Float object.
|
abstract void |
writeFloat(float[] value) |
void |
writeFloat(float[] value,
java.text.DecimalFormat format)
Writes a float array with the specified decimal format.
|
void |
writeFloat(float value,
java.text.DecimalFormat format)
Writes a float value with the specified decimal format.
|
abstract void |
writeHex(byte[] bytes)
Writes a byte array as hexadecimal string.
|
void |
writeInstant(java.time.Instant instant)
Writes an Instant value as an ISO-8601 formatted string.
|
abstract void |
writeInt16(short value)
Writes a short value as an integer.
|
void |
writeInt16(short[] value)
Writes a short array as integers.
|
abstract void |
writeInt32(int value)
Writes an int value.
|
abstract void |
writeInt32(int[] value)
Writes an int array as integers.
|
void |
writeInt32(int value,
java.text.DecimalFormat format)
Writes an int value with the specified decimal format.
|
abstract void |
writeInt32(java.lang.Integer i)
Writes an Integer object.
|
void |
writeInt32(int value,
java.lang.String format)
Writes an int value with the specified string format.
|
abstract void |
writeInt64(long i)
Writes a long value.
|
abstract void |
writeInt64(java.lang.Long i)
Writes a Long object.
|
abstract void |
writeInt64(long[] value)
Writes a long array as integers.
|
void |
writeInt64Null()
Writes a null long value using the current context features.
|
void |
writeInt64Null(long features) |
abstract void |
writeInt8(byte value)
Writes a byte value as an integer.
|
abstract void |
writeInt8(byte[] value)
Writes a byte array as integers.
|
abstract void |
writeListInt32(java.util.List<java.lang.Integer> values)
Writes a list of Integer values as integers.
|
abstract void |
writeListInt64(java.util.List<java.lang.Long> values)
Writes a list of Long values as integers.
|
abstract void |
writeLocalDate(java.time.LocalDate date)
Writes a LocalDate value.
|
abstract void |
writeLocalDateTime(java.time.LocalDateTime dateTime)
Writes a LocalDateTime value.
|
protected boolean |
writeLocalDateWithFormat(java.time.LocalDate date) |
abstract void |
writeLocalTime(java.time.LocalTime time)
Writes a LocalTime value.
|
void |
writeMillis(long i)
Writes a timestamp value as a long integer.
|
void |
writeName(int name)
Writes a field name as an integer value in a JSON object.
|
void |
writeName(long name)
Writes a field name as a long value in a JSON object.
|
void |
writeName(java.lang.String name) |
abstract void |
writeName10Raw(long name0,
long name1)
Writes a 10-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName11Raw(long name0,
long name2)
Writes an 11-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName12Raw(long name0,
long name2)
Writes a 12-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName13Raw(long name0,
long name2)
Writes a 13-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName14Raw(long name0,
long name2)
Writes a 14-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName15Raw(long name0,
long name2)
Writes a 15-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName16Raw(long name0,
long name2)
Writes a 16-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName2Raw(long name)
Writes a 2-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName3Raw(long name)
Writes a 3-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName4Raw(long name)
Writes a 4-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName5Raw(long name)
Writes a 5-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName6Raw(long name)
Writes a 6-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName7Raw(long name)
Writes a 7-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName8Raw(long name0)
Writes an 8-character field name as raw bytes without any escaping or formatting.
|
abstract void |
writeName9Raw(long name0,
int name1)
Writes a 9-character field name as raw bytes without any escaping or formatting.
|
void |
writeNameAny(java.lang.Object name)
Writes a field name of any type in a JSON object.
|
abstract void |
writeNameRaw(byte[] bytes)
Writes raw bytes representing a field name without any escaping or formatting.
|
void |
writeNameRaw(byte[] bytes,
int offset,
int len)
Writes raw bytes representing a field name without any escaping or formatting.
|
void |
writeNameRaw(byte[] name,
long nameHash)
Writes raw bytes representing a field name without any escaping or formatting.
|
abstract void |
writeNameRaw(char[] chars)
Writes raw characters representing a field name without any escaping or formatting.
|
abstract void |
writeNameRaw(char[] bytes,
int offset,
int len)
Writes raw characters representing a field name without any escaping or formatting.
|
void |
writeNameValue(java.lang.String name,
java.lang.Object value)
Writes a field name and its value as a key-value pair in a JSON object.
|
abstract void |
writeNull()
Writes a null value.
|
void |
writeNumberNull()
Writes a null number value using the current context features.
|
void |
writeNumberNull(long features)
Writes a null number value using the specified features.
|
void |
writeObjectNull(java.lang.Class<?> fieldClass)
Writes a null object value.
|
abstract void |
writeOffsetDateTime(java.time.OffsetDateTime dateTime)
Writes an OffsetDateTime value.
|
abstract void |
writeOffsetTime(java.time.OffsetTime dateTime)
Writes an OffsetTime value.
|
void |
writeRaw(byte b)
Writes a raw byte without any escaping or formatting.
|
abstract void |
writeRaw(byte[] bytes)
Writes raw bytes without any escaping or formatting.
|
abstract void |
writeRaw(char ch)
Writes a raw character without any escaping or formatting.
|
void |
writeRaw(char[] chars)
Writes raw characters without any escaping or formatting.
|
void |
writeRaw(char[] chars,
int off,
int charslen)
Writes raw characters without any escaping or formatting.
|
void |
writeRaw(char c0,
char c1)
Writes two raw characters without any escaping or formatting.
|
abstract void |
writeRaw(java.lang.String str)
Writes a raw string without any escaping or formatting.
|
boolean |
writeReference(int index,
java.lang.Object object)
Writes a reference to the specified object at the given index.
|
void |
writeReference(java.lang.Object object)
Deprecated.
This method is deprecated and will be removed in a future version
|
abstract void |
writeReference(java.lang.String path)
Writes a reference to a previously serialized object.
|
abstract void |
writeString(boolean value)
Writes a boolean value as a string.
|
void |
writeString(boolean[] value)
Writes a boolean array as strings.
|
abstract void |
writeString(byte value)
Writes a byte value as a string.
|
void |
writeString(byte[] value)
Writes a byte array as strings.
|
abstract void |
writeString(char[] chars)
Writes a string from character array.
|
abstract void |
writeString(char[] chars,
int off,
int len)
Writes a string from character array with specified offset and length.
|
abstract void |
writeString(char[] chars,
int off,
int len,
boolean quote)
Writes a string from character array with specified offset and length.
|
void |
writeString(double value)
Writes a double value as a string.
|
void |
writeString(double[] value)
Writes a double array as strings.
|
void |
writeString(float value)
Writes a float value as a string.
|
void |
writeString(float[] value)
Writes a float array as strings.
|
abstract void |
writeString(int value)
Writes an int value as a string.
|
void |
writeString(int[] value)
Writes an int array as strings.
|
void |
writeString(java.util.List<java.lang.String> list)
Writes a list of strings as a JSON array.
|
abstract void |
writeString(long value)
Writes a long value as a string.
|
void |
writeString(long[] value)
Writes a long array as strings.
|
void |
writeString(java.io.Reader reader)
Writes a string from a Reader.
|
abstract void |
writeString(short value)
Writes a short value as a string.
|
void |
writeString(short[] value)
Writes a short array as strings.
|
abstract void |
writeString(java.lang.String str)
Writes a string value.
|
void |
writeString(java.lang.String[] strings)
Writes an array of strings as a JSON array.
|
abstract void |
writeStringLatin1(byte[] value)
Writes a string from Latin-1 encoded bytes.
|
void |
writeStringNull()
Writes a null string value.
|
abstract void |
writeStringUTF16(byte[] value)
Writes a string from UTF-16 encoded bytes.
|
void |
writeSymbol(int symbol)
Writes a symbol as a JSON value.
|
void |
writeSymbol(java.lang.String string)
Writes a symbol string.
|
abstract void |
writeTimeHHMMSS8(int hour,
int minute,
int second)
Writes a time in 8-character format (HH:mm:ss).
|
boolean |
writeTypeName(byte[] typeName,
long typeNameHash)
Writes a type name for the current object using byte array and hash.
|
void |
writeTypeName(java.lang.String typeName)
Writes a type name for the current object.
|
abstract void |
writeUUID(java.util.UUID value)
Writes a UUID value.
|
abstract void |
writeZonedDateTime(java.time.ZonedDateTime dateTime)
Writes a ZonedDateTime value.
|
static final long WRITE_ARRAY_NULL_MASK
static final byte PRETTY_NON
static final byte PRETTY_TAB
static final byte PRETTY_2_SPACE
static final byte PRETTY_4_SPACE
static final long NONE_DIRECT_FEATURES
public final JSONWriter.Context context
public final boolean utf8
public final boolean utf16
public final boolean jsonb
public final boolean useSingleQuote
public final SymbolTable symbolTable
protected final java.nio.charset.Charset charset
protected final char quote
protected final int maxArraySize
protected boolean startObject
protected int level
protected int off
protected java.lang.Object rootObject
protected java.util.IdentityHashMap<java.lang.Object,JSONWriter.Path> refs
protected JSONWriter.Path path
protected java.lang.String lastReference
protected byte pretty
protected java.lang.Object attachment
public static final long MASK_FIELD_BASED
public static final long MASK_IGNORE_NONE_SERIALIZABLE
public static final long MAKS_ERROR_ON_NONE_SERIALIZABLE
public static final long MASK_BEAN_TO_ARRAY
public static final long MASK_WRITE_MAP_NULL_VALUE
public static final long MASK_BROWSER_COMPATIBLE
public static final long MASK_NULL_AS_DEFAULT_VALUE
public static final long MASK_WRITE_BOOLEAN_AS_NUMBER
public static final long MASK_WRITE_NON_STRING_VALUE_AS_STRING
public static final long MASK_WRITE_CLASS_NAME
public static final long MASK_NOT_WRITE_ROOT_CLASSNAME
public static final long MASK_NOT_WRITE_HASHMAP_ARRAY_LIST_CLASS_NAME
public static final long MASK_NOT_WRITE_DEFAULT_VALUE
public static final long MASK_WRITE_ENUMS_USING_NAME
public static final long MASK_WRITE_ENUM_USING_TO_STRING
public static final long MASK_IGNORE_ERROR_GETTER
public static final long MASK_PRETTY_FORMAT
public static final long MASK_REFERENCE_DETECTION
public static final long MASK_WRITE_BIG_DECIMAL_AS_PLAIN
public static final long MASK_USE_SINGLE_QUOTES
public static final long MASK_WRITE_NULL_LIST_AS_EMPTY
public static final long MASK_WRITE_NULL_STRING_AS_EMPTY
public static final long MASK_WRITE_NULL_NUMBER_AS_ZERO
public static final long MASK_WRITE_NULL_BOOLEAN_AS_FALSE
public static final long MASK_NOT_WRITE_EMPTY_ARRAY
public static final long MASK_WRITE_NON_STRING_KEY_AS_STRING
public static final long MASK_WRITE_PAIR_AS_JAVA_BEAN
public static final long MASK_ESCAPE_NONE_ASCII
public static final long MASK_IGNORE_NON_FIELD_GETTER
public static final long MASK_WRITE_LONG_AS_STRING
public static final long MASK_BROWSER_SECURE
public static final long MASK_WRITE_ENUM_USING_ORDINAL
public static final long MASK_UNQUOTE_FIELD_NAME
public static final long MASK_NOT_WRITE_NUMBER_CLASS_NAME
public static final long MASK_WRITE_FLOAT_SPECIAL_AS_STRING
protected JSONWriter(JSONWriter.Context context, SymbolTable symbolTable, boolean jsonb, java.nio.charset.Charset charset)
public final java.nio.charset.Charset getCharset()
public final boolean isUTF8()
public final boolean isUTF16()
public final boolean isIgnoreNoneSerializable()
public final boolean isIgnoreNoneSerializable(java.lang.Object object)
object - the object to checkpublic final SymbolTable getSymbolTable()
public final void config(JSONWriter.Feature... features)
features - the features to enablepublic final void config(JSONWriter.Feature feature, boolean state)
feature - the feature to configurestate - true to enable the feature, false to disable itpublic final JSONWriter.Context getContext()
public final int level()
public final void setRootObject(java.lang.Object rootObject)
rootObject - the root object to setpublic final java.lang.String setPath(java.lang.String name,
java.lang.Object object)
name - the name of the path segmentobject - the object to set the path forpublic final java.lang.String setPath(FieldWriter fieldWriter, java.lang.Object object)
fieldWriter - the field writer to use for path generationobject - the object to set the path forpublic final java.lang.String setPath0(FieldWriter fieldWriter, java.lang.Object object)
fieldWriter - the field writer to use for path generationobject - the object to set the path forpublic final void addManagerReference(java.lang.Object object)
object - the object to add a manager reference forpublic final boolean writeReference(int index,
java.lang.Object object)
index - the index to set the path forobject - the object to write a reference forpublic final java.lang.String setPath(int index,
java.lang.Object object)
index - the index to set the path forobject - the object to set the path forpublic final java.lang.String setPath0(int index,
java.lang.Object object)
index - the index to set the path forobject - the object to set the path forpublic final void popPath(java.lang.Object object)
object - the object to remove the path forpublic final void popPath0(java.lang.Object object)
object - the object to remove the path forpublic final boolean hasFilter()
public final boolean hasFilter(long feature)
feature - the feature to checkpublic final boolean hasFilter(boolean containsNoneFieldGetter)
containsNoneFieldGetter - whether to check for the IgnoreNonFieldGetter featurepublic final boolean isWriteNulls()
public final boolean isRefDetect()
public final boolean isUseSingleQuotes()
public final boolean isRefDetect(java.lang.Object object)
object - the object to checkpublic final boolean containsReference(java.lang.Object value)
value - the object to checkpublic final java.lang.String getPath(java.lang.Object value)
value - the object to get the path forpublic java.lang.String getPath()
public final boolean removeReference(java.lang.Object value)
value - the object whose reference should be removedpublic final boolean isBeanToArray()
public final boolean isEnabled(JSONWriter.Feature feature)
feature - the feature to checkpublic final boolean isEnabled(long feature)
feature - the feature to checkpublic final long getFeatures()
public final long getFeatures(long features)
features - the additional features to combine with the current featurespublic final boolean isIgnoreErrorGetter()
public final boolean isWriteTypeInfo(java.lang.Object object,
java.lang.Class fieldClass)
object - the object to checkfieldClass - the field class to checkpublic final boolean isWriteTypeInfo(java.lang.Object object,
java.lang.reflect.Type fieldType)
object - the object to checkfieldType - the field type to checkprivate static boolean isWriteTypeInfoGenericArray(java.lang.reflect.GenericArrayType fieldType,
java.lang.Class objectClass)
public final boolean isWriteTypeInfo(java.lang.Object object)
object - the object to check for type information writingpublic final boolean isWriteTypeInfo(java.lang.Object object,
java.lang.reflect.Type fieldType,
long features)
object - the object to checkfieldType - the field type to checkfeatures - the features to considerpublic final boolean isWriteTypeInfo(java.lang.Object object,
java.lang.Class fieldClass,
long features)
object - the object to checkfieldClass - the field class to checkfeatures - the features to considerpublic final boolean isWriteMapTypeInfo(java.lang.Object object,
java.lang.Class fieldClass,
long features)
object - the object to checkfieldClass - the field class to checkfeatures - the features to considerpublic final boolean isWriteTypeInfo(java.lang.Object object,
long features)
object - the object to checkfeatures - the features to considerpublic final ObjectWriter getObjectWriter(java.lang.Class objectClass)
objectClass - the class of objects to be serializedpublic final ObjectWriter getObjectWriter(java.lang.Class objectClass, java.lang.String format)
objectClass - the class of objects to be serializedformat - the format string to use for serializationpublic final ObjectWriter getObjectWriter(java.lang.reflect.Type objectType, java.lang.Class objectClass)
objectType - the type of objects to be serializedobjectClass - the class of objects to be serializedpublic static JSONWriter of()
Example usage:
try (JSONWriter writer = JSONWriter.of()) {
writer.writeAny(object);
String json = writer.toString();
}
public static JSONWriter of(ObjectWriterProvider provider, JSONWriter.Feature... features)
provider - the object writer provider to usefeatures - the features to enablepublic static JSONWriter of(JSONWriter.Context context)
context - the context to usepublic static JSONWriter of(JSONWriter.Feature... features)
features - the features to enablepublic static JSONWriter ofUTF16(JSONWriter.Feature... features)
features - the features to enable for the new JSONWriterpublic static JSONWriter ofJSONB()
public static JSONWriter ofJSONB(JSONWriter.Context context)
context - the context to use for the new JSONWriterpublic static JSONWriter ofJSONB(JSONWriter.Context context, SymbolTable symbolTable)
context - the context to use for the new JSONWritersymbolTable - the symbol table to use for the new JSONWriterpublic static JSONWriter ofJSONB(JSONWriter.Feature... features)
features - the features to enable for the new JSONWriterpublic static JSONWriter ofJSONB(SymbolTable symbolTable)
symbolTable - the symbol table to use for the new JSONWriterpublic static JSONWriter ofPretty()
public static JSONWriter ofPretty(JSONWriter writer)
writer - the JSONWriter instance to enable pretty formatting onpublic static JSONWriter ofUTF8()
public static JSONWriter ofUTF8(JSONWriter.Context context)
context - the context to use for the new JSONWriterpublic static JSONWriter ofUTF8(JSONWriter.Feature... features)
features - the features to enable for the new JSONWriterpublic void writeBinary(byte[] bytes)
bytes - the byte array to writepublic abstract void writeBase64(byte[] bytes)
bytes - the byte array to encode and writepublic abstract void writeHex(byte[] bytes)
bytes - the byte array to encode and writeprotected abstract void write0(char ch)
ch - the character to writepublic abstract void writeRaw(java.lang.String str)
str - the string to writepublic abstract void writeRaw(byte[] bytes)
bytes - the bytes to writepublic void writeRaw(byte b)
b - the byte to writeJSONException - if the operation is not supported by this implementationpublic void writeNameRaw(byte[] bytes,
int offset,
int len)
bytes - the bytes to writeoffset - the offset in the byte arraylen - the number of bytes to writeJSONException - if the operation is not supported by this implementationpublic final void writeRaw(char[] chars)
chars - the character array to writepublic void writeRaw(char[] chars,
int off,
int charslen)
chars - the character array to writeoff - the offset in the character arraycharslen - the number of characters to writeJSONException - if the operation is not supported by this implementationpublic abstract void writeChar(char ch)
ch - the character to writepublic abstract void writeRaw(char ch)
ch - the character to writepublic void writeRaw(char c0,
char c1)
c0 - the first character to writec1 - the second character to writeJSONException - if the operation is not supported by this implementationpublic abstract void writeNameRaw(byte[] bytes)
bytes - the bytes to writepublic abstract void writeName2Raw(long name)
name - the 2-character field name as a long valuepublic abstract void writeName3Raw(long name)
name - the 3-character field name as a long valuepublic abstract void writeName4Raw(long name)
name - the 4-character field name as a long valuepublic abstract void writeName5Raw(long name)
name - the 5-character field name as a long valuepublic abstract void writeName6Raw(long name)
name - the 6-character field name as a long valuepublic abstract void writeName7Raw(long name)
name - the 7-character field name as a long valuepublic abstract void writeName8Raw(long name0)
name0 - the 8-character field name as a long valuepublic abstract void writeName9Raw(long name0,
int name1)
name0 - the first 8 characters of the field name as a long valuename1 - the 9th character of the field name as an integer valuepublic abstract void writeName10Raw(long name0,
long name1)
name0 - the first 8 characters of the field name as a long valuename1 - the last 2 characters of the field name as a long valuepublic abstract void writeName11Raw(long name0,
long name2)
name0 - the first 8 characters of the field name as a long valuename2 - the last 3 characters of the field name as a long valuepublic abstract void writeName12Raw(long name0,
long name2)
name0 - the first 8 characters of the field name as a long valuename2 - the last 4 characters of the field name as a long valuepublic abstract void writeName13Raw(long name0,
long name2)
name0 - the first 8 characters of the field name as a long valuename2 - the last 5 characters of the field name as a long valuepublic abstract void writeName14Raw(long name0,
long name2)
name0 - the first 8 characters of the field name as a long valuename2 - the last 6 characters of the field name as a long valuepublic abstract void writeName15Raw(long name0,
long name2)
name0 - the first 8 characters of the field name as a long valuename2 - the last 7 characters of the field name as a long valuepublic abstract void writeName16Raw(long name0,
long name2)
name0 - the first 8 characters of the field name as a long valuename2 - the last 8 characters of the field name as a long valuepublic void writeSymbol(int symbol)
symbol - the symbol to writeJSONException - if the operation is not supported by this implementationpublic void writeNameRaw(byte[] name,
long nameHash)
name - the bytes representing the field namenameHash - the hash of the field nameJSONException - if the operation is not supported by this implementationpublic static boolean isWriteAsString(long value,
long features)
protected static boolean isWriteAsString(java.math.BigInteger value,
long features)
protected static boolean isWriteAsString(java.math.BigDecimal value,
long features)
public abstract void writeNameRaw(char[] chars)
chars - the character array to writepublic abstract void writeNameRaw(char[] bytes,
int offset,
int len)
bytes - the character array to writeoffset - the offset in the character arraylen - the number of characters to writepublic void writeName(java.lang.String name)
public final void writeNameValue(java.lang.String name,
java.lang.Object value)
name - the field namevalue - the field valuepublic final void writeName(long name)
name - the field name as a long valuepublic final void writeName(int name)
name - the field name as an integer valuepublic void writeNameAny(java.lang.Object name)
name - the field name of any typepublic abstract void startObject()
public abstract void endObject()
public abstract void startArray()
public void startArray(int size)
size - the expected number of elements in the arrayJSONException - if the operation is not supported by this implementationpublic void startArray0()
public void startArray1()
public void startArray2()
public void startArray3()
public void startArray4()
public void startArray5()
public void startArray6()
public void startArray7()
public void startArray8()
public void startArray9()
public void startArray10()
public void startArray11()
public void startArray12()
public void startArray13()
public void startArray14()
public void startArray15()
public void startArray(java.lang.Object array,
int size)
array - the array to serializesize - the expected number of elements in the arrayJSONException - if the operation is not supported by this implementationpublic abstract void endArray()
public abstract void writeComma()
public abstract void writeColon()
public void writeInt16(short[] value)
value - the short array to write, can be nullpublic abstract void writeInt8(byte value)
value - the byte value to writepublic abstract void writeInt8(byte[] value)
value - the byte array to writepublic abstract void writeInt16(short value)
value - the short value to writepublic abstract void writeInt32(int[] value)
value - the int array to writepublic abstract void writeInt32(int value)
value - the int value to writepublic abstract void writeInt32(java.lang.Integer i)
i - the Integer object to writepublic final void writeInt32(int value,
java.text.DecimalFormat format)
value - the int value to writeformat - the decimal format to use, or null to use default formattingpublic final void writeInt32(int value,
java.lang.String format)
value - the int value to writeformat - the string format to use, or null to use default formattingpublic abstract void writeInt64(long i)
i - the long value to writepublic abstract void writeInt64(java.lang.Long i)
i - the Long object to writepublic void writeMillis(long i)
i - the timestamp value to write as millisecondspublic abstract void writeInt64(long[] value)
value - the long array to writepublic abstract void writeListInt64(java.util.List<java.lang.Long> values)
values - the list of Long values to writepublic abstract void writeListInt32(java.util.List<java.lang.Integer> values)
values - the list of Integer values to writepublic abstract void writeFloat(float value)
value - the float value to writepublic final void writeFloat(float value,
java.text.DecimalFormat format)
value - the float value to writeformat - the decimal format to use, or null to use default formattingpublic abstract void writeFloat(float[] value)
public final void writeFloat(float[] value,
java.text.DecimalFormat format)
value - the float array to write, can be nullformat - the decimal format to use, or null to use default formattingpublic final void writeFloat(java.lang.Float value)
value - the Float object to write, can be nullpublic abstract void writeDouble(double value)
value - the double value to writepublic final void writeDouble(double value,
java.text.DecimalFormat format)
value - the double value to writeformat - the decimal format to use, or null to use default formattingpublic void writeDoubleArray(double value0,
double value1)
value0 - the first double value to writevalue1 - the second double value to writepublic final void writeDouble(double[] value,
java.text.DecimalFormat format)
value - the double array to write, can be nullformat - the decimal format to use, or null to use default formattingpublic abstract void writeDouble(double[] value)
value - the double array to writepublic abstract void writeBool(boolean value)
value - the boolean value to writepublic void writeBool(boolean[] value)
value - the boolean array to write, can be nullpublic abstract void writeNull()
public void writeObjectNull(java.lang.Class<?> fieldClass)
JSONWriter.Feature.NullAsDefaultValue is enabled, a default empty object or null character is writtenfieldClass - the class of the field being writtenpublic void writeStringNull()
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullStringAsEmpty is enabled, an empty string is writtenpublic void writeArrayNull()
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullListAsEmpty is enabled, an empty array is writtenpublic void writeArrayNull(long features)
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullListAsEmpty is enabled, an empty array is writtenfeatures - the features to use for serializationpublic final void writeNumberNull()
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullNumberAsZero is enabled, zero is writtenpublic final void writeNumberNull(long features)
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullNumberAsZero is enabled, zero is writtenfeatures - the features to use for serializationpublic final void writeDecimalNull()
JSONWriter.Feature.NullAsDefaultValue is enabled, 0.0 is writtenJSONWriter.Feature.WriteNullNumberAsZero is enabled, zero is writtenpublic final void writeDecimalNull(long features)
JSONWriter.Feature.NullAsDefaultValue is enabled, 0.0 is writtenJSONWriter.Feature.WriteNullNumberAsZero is enabled, zero is writtenfeatures - the features to use for serializationpublic final void writeInt64Null(long features)
public final void writeInt64Null()
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullNumberAsZero is enabled, zero is writtenpublic final void writeBooleanNull()
JSONWriter.Feature.NullAsDefaultValue or JSONWriter.Feature.WriteNullBooleanAsFalse is enabled, false is writtenpublic final void writeDecimal(java.math.BigDecimal value)
value - the BigDecimal value to write, can be nullpublic final void writeDecimal(java.math.BigDecimal value,
long features)
value - the BigDecimal value to write, can be nullfeatures - the features to use for serializationpublic abstract void writeDecimal(java.math.BigDecimal value,
long features,
java.text.DecimalFormat format)
value - the BigDecimal value to write, can be nullfeatures - the features to use for serializationformat - the decimal format to use, or null to use default formattingpublic void writeEnum(java.lang.Enum e)
JSONWriter.Feature.WriteEnumUsingToString is enabled, the enum is written using its toString() methodJSONWriter.Feature.WriteEnumsUsingName is enabled, the enum is written using its name()e - the Enum value to write, can be nullpublic final void writeBigInt(java.math.BigInteger value)
value - the BigInteger value to write, can be nullpublic abstract void writeBigInt(java.math.BigInteger value,
long features)
value - the BigInteger value to write, can be nullfeatures - the features to use for serializationpublic abstract void writeUUID(java.util.UUID value)
value - the UUID to write, can be nullpublic final void checkAndWriteTypeName(java.lang.Object object,
java.lang.Class fieldClass)
object - the object being serializedfieldClass - the expected field class typepublic void writeTypeName(java.lang.String typeName)
typeName - the type name to writeJSONException - if the operation is not supported by this implementationpublic boolean writeTypeName(byte[] typeName,
long typeNameHash)
typeName - the type name as byte arraytypeNameHash - the hash of the type nameJSONException - if the operation is not supported by this implementationpublic final void writeString(java.io.Reader reader)
reader - the Reader to read characters fromJSONException - if an I/O error occurs while reading from the Readerpublic abstract void writeString(java.lang.String str)
str - the string to write, can be nullpublic abstract void writeString(boolean value)
value - the boolean value to writepublic abstract void writeString(byte value)
value - the byte value to writepublic abstract void writeString(short value)
value - the short value to writepublic void writeString(boolean[] value)
value - the boolean array to writepublic void writeString(byte[] value)
value - the byte array to writepublic void writeString(short[] value)
value - the short array to writepublic void writeString(int[] value)
value - the int array to writepublic void writeString(long[] value)
value - the long array to writepublic void writeString(float[] value)
value - the float array to writepublic void writeString(double[] value)
value - the double array to writepublic abstract void writeString(int value)
value - the int value to writepublic void writeString(float value)
value - the float value to writepublic void writeString(double value)
value - the double value to writepublic abstract void writeString(long value)
value - the long value to writepublic abstract void writeStringLatin1(byte[] value)
value - the Latin-1 encoded bytes to writepublic abstract void writeStringUTF16(byte[] value)
value - the UTF-16 encoded bytes to writepublic void writeString(java.util.List<java.lang.String> list)
list - the list of strings to write, can be nullpublic void writeString(java.lang.String[] strings)
strings - the array of strings to write, can be nullpublic void writeSymbol(java.lang.String string)
string - the symbol string to writepublic abstract void writeString(char[] chars)
chars - the character array to writepublic abstract void writeString(char[] chars,
int off,
int len)
chars - the character array to writeoff - the offset in the arraylen - the number of characters to writepublic abstract void writeString(char[] chars,
int off,
int len,
boolean quote)
chars - the character array to writeoff - the offset in the arraylen - the number of characters to writequote - whether to quote the stringpublic abstract void writeLocalDate(java.time.LocalDate date)
date - the LocalDate to writeprotected final boolean writeLocalDateWithFormat(java.time.LocalDate date)
public abstract void writeLocalDateTime(java.time.LocalDateTime dateTime)
dateTime - the LocalDateTime to writepublic abstract void writeLocalTime(java.time.LocalTime time)
time - the LocalTime to writepublic abstract void writeZonedDateTime(java.time.ZonedDateTime dateTime)
dateTime - the ZonedDateTime to writepublic abstract void writeOffsetDateTime(java.time.OffsetDateTime dateTime)
dateTime - the OffsetDateTime to writepublic abstract void writeOffsetTime(java.time.OffsetTime dateTime)
dateTime - the OffsetTime to writepublic void writeInstant(java.time.Instant instant)
instant - the Instant to write, can be nullpublic abstract void writeDateTime14(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
year - the yearmonth - the month (1-12)dayOfMonth - the day of month (1-31)hour - the hour (0-23)minute - the minute (0-59)second - the second (0-59)public abstract void writeDateTime19(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second)
year - the yearmonth - the month (1-12)dayOfMonth - the day of month (1-31)hour - the hour (0-23)minute - the minute (0-59)second - the second (0-59)public abstract void writeDateTimeISO8601(int year,
int month,
int dayOfMonth,
int hour,
int minute,
int second,
int millis,
int offsetSeconds,
boolean timeZone)
year - the yearmonth - the month (1-12)dayOfMonth - the day of month (1-31)hour - the hour (0-23)minute - the minute (0-59)second - the second (0-59)millis - the millisecond (0-999)offsetSeconds - the timezone offset in secondstimeZone - whether to include timezone informationpublic abstract void writeDateYYYMMDD8(int year,
int month,
int dayOfMonth)
year - the yearmonth - the month (1-12)dayOfMonth - the day of month (1-31)public abstract void writeDateYYYMMDD10(int year,
int month,
int dayOfMonth)
year - the yearmonth - the month (1-12)dayOfMonth - the day of month (1-31)public abstract void writeTimeHHMMSS8(int hour,
int minute,
int second)
hour - the hour (0-23)minute - the minute (0-59)second - the second (0-59)public abstract void write(java.util.List array)
array - the list to writepublic final void write(JSONObject map)
map - the JSONObject to writepublic void write(java.util.Map<?,?> map)
map - the Map to write, can be nullpublic void writeAny(java.lang.Object value)
value - the object to write, can be nullpublic final void writeAs(java.lang.Object value,
java.lang.Class type)
value - the object to writetype - the type to serialize the object aspublic abstract void writeReference(java.lang.String path)
path - the JSON Pointer path to the referenced objectpublic abstract void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.lang.RuntimeException - if an I/O error occurspublic abstract int size()
public abstract byte[] getBytes()
public abstract byte[] getBytes(java.nio.charset.Charset charset)
charset - the charset to use for encodingpublic void flushTo(java.io.Writer to)
to - the Writer to flush content toJSONException - if an I/O error occurs while writing to the Writerpublic abstract int flushTo(java.io.OutputStream to)
throws java.io.IOException
to - the OutputStream to flush content tojava.io.IOException - if an I/O error occurs while writing to the OutputStreampublic abstract int flushTo(java.io.OutputStream out,
java.nio.charset.Charset charset)
throws java.io.IOException
out - the OutputStream to flush content tocharset - the charset to use for encodingjava.io.IOException - if an I/O error occurs while writing to the OutputStreamprotected static java.lang.IllegalArgumentException illegalYear(int year)
public final void incrementIndent()
public final void decrementIdent()
public void println()
public final void writeReference(java.lang.Object object)
object - the object for which to write a referenceprotected final int newCapacity(int minCapacity,
int oldCapacity)
minCapacity - the minimum required capacityoldCapacity - the current capacity of the bufferJSONLargeObjectException - if the required capacity exceeds the maximum allowed array sizepublic java.lang.Object getAttachment()
public void setAttachment(java.lang.Object attachment)
attachment - the attachment object to setprotected final void overflowLevel()
JSONException - with a message indicating the level is too largepublic int getOffset()
public void setOffset(int offset)
offset - the offset to setpublic abstract java.lang.Object ensureCapacity(int minCapacity)
minCapacity - the minimum capacity required