Class FastJsonWriter
java.lang.Object
org.dominokit.jacksonapt.stream.impl.FastJsonWriter
- All Implemented Interfaces:
JsonWriter
public class FastJsonWriter extends java.lang.Object implements JsonWriter
FastJsonWriter class.
- Version:
- $Id: $
- Author:
- nicolasmorel
-
Constructor Summary
Constructors Constructor Description FastJsonWriter(java.lang.StringBuilder out)Creates a new instance that writes a JSON-encoded stream toout. -
Method Summary
Modifier and Type Method Description FastJsonWriterbeginArray()Begins encoding a new array.FastJsonWriterbeginObject()Begins encoding a new object.FastJsonWritercancelName()cancelNamevoidclose()Flushes and closes this writer and the underlyingStringBuilder.FastJsonWriterendArray()Ends encoding the current array.FastJsonWriterendObject()Ends encoding the current object.voidflush()Ensures all buffered data is written to the underlyingStringBuilderand flushes that writer.java.lang.StringgetOutput()getOutputbooleangetSerializeNulls()getSerializeNullsbooleanisLenient()Returns true if this writer has relaxed syntax rules.FastJsonWritername(java.lang.String name)Encodes the property name.FastJsonWriternullValue()Encodesnull.FastJsonWriterrawValue(java.lang.Object value)Encodesvalue.toString() as is.voidsetIndent(java.lang.String indent)Sets the indentation string to be repeated for each level of indentation in the encoded document.voidsetLenient(boolean lenient)Configure this writer to relax its syntax rules.voidsetSerializeNulls(boolean serializeNulls)Sets whether object members are serialized when their value is null.FastJsonWriterunescapeName(java.lang.String name)Encodes the property name without escaping it.FastJsonWriterunescapeValue(java.lang.String value)Encodesvaluewithout escaping it.FastJsonWritervalue(boolean value)Encodesvalue.FastJsonWritervalue(double value)Encodesvalue.FastJsonWritervalue(long value)Encodesvalue.FastJsonWritervalue(java.lang.Number value)Encodesvalue.FastJsonWritervalue(java.lang.String value)Encodesvalue.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
FastJsonWriter
public FastJsonWriter(java.lang.StringBuilder out)Creates a new instance that writes a JSON-encoded stream toout.- Parameters:
out- aStringBuilderobject.
-
-
Method Details
-
setIndent
public final void setIndent(java.lang.String indent)Sets the indentation string to be repeated for each level of indentation in the encoded document. Ifindent.isEmpty()the encoded document will be compact. Otherwise the encoded document will be more human-readable.- Specified by:
setIndentin interfaceJsonWriter- Parameters:
indent- a string containing only whitespace.
-
setLenient
public final void setLenient(boolean lenient)Configure this writer to relax its syntax rules. By default, this writer only emits well-formed JSON as specified by RFC 4627. Setting the writer to lenient permits the following:- Top-level values of any type. With strict writing, the top-level value must be an object or an array.
- Numbers may be
NaNsorinfinities.
- Specified by:
setLenientin interfaceJsonWriter- Parameters:
lenient- a boolean.
-
isLenient
public boolean isLenient()Returns true if this writer has relaxed syntax rules.- Returns:
- a boolean.
-
setSerializeNulls
public final void setSerializeNulls(boolean serializeNulls)Sets whether object members are serialized when their value is null. This has no impact on array elements. The default is true.- Specified by:
setSerializeNullsin interfaceJsonWriter- Parameters:
serializeNulls- a boolean.
-
getSerializeNulls
public final boolean getSerializeNulls()getSerializeNulls
Returns true if object members are serialized when their value is null. This has no impact on array elements. The default is true.
- Specified by:
getSerializeNullsin interfaceJsonWriter- Returns:
- a boolean.
-
beginArray
Begins encoding a new array. Each call to this method must be paired with a call toJsonWriter.endArray().- Specified by:
beginArrayin interfaceJsonWriter- Returns:
- this writer.
-
endArray
Ends encoding the current array.- Specified by:
endArrayin interfaceJsonWriter- Returns:
- this writer.
-
beginObject
Begins encoding a new object. Each call to this method must be paired with a call toJsonWriter.endObject().- Specified by:
beginObjectin interfaceJsonWriter- Returns:
- this writer.
-
endObject
Ends encoding the current object.- Specified by:
endObjectin interfaceJsonWriter- Returns:
- this writer.
-
name
Encodes the property name.- Specified by:
namein interfaceJsonWriter- Parameters:
name- the name of the forthcoming value. May not be null.- Returns:
- this writer.
-
unescapeName
Encodes the property name without escaping it.- Specified by:
unescapeNamein interfaceJsonWriter- Parameters:
name- the name of the forthcoming value. May not be null.- Returns:
- this writer.
-
value
Encodesvalue.- Specified by:
valuein interfaceJsonWriter- Parameters:
value- the literal string value, or null to encode a null literal.- Returns:
- this writer.
-
unescapeValue
Encodesvaluewithout escaping it.- Specified by:
unescapeValuein interfaceJsonWriter- Parameters:
value- the literal string value, or null to encode a null literal.- Returns:
- this writer.
-
nullValue
Encodesnull.- Specified by:
nullValuein interfaceJsonWriter- Returns:
- this writer.
-
cancelName
cancelName
- Specified by:
cancelNamein interfaceJsonWriter- Returns:
- a
JsonWriterobject.
-
value
Encodesvalue.- Specified by:
valuein interfaceJsonWriter- Parameters:
value- a boolean.- Returns:
- this writer.
-
value
Encodesvalue.- Specified by:
valuein interfaceJsonWriter- Parameters:
value- a finite value. May not beNaNsorinfinities.- Returns:
- this writer.
-
value
Encodesvalue.- Specified by:
valuein interfaceJsonWriter- Parameters:
value- a long.- Returns:
- this writer.
-
value
Encodesvalue.- Specified by:
valuein interfaceJsonWriter- Parameters:
value- a finite value. May not beNaNsorinfinities.- Returns:
- this writer.
-
rawValue
Encodesvalue.toString() as is.- Specified by:
rawValuein interfaceJsonWriter- Parameters:
value- a value .- Returns:
- this writer.
-
flush
public void flush()Ensures all buffered data is written to the underlyingStringBuilderand flushes that writer.- Specified by:
flushin interfaceJsonWriter
-
close
public void close()Flushes and closes this writer and the underlyingStringBuilder.- Specified by:
closein interfaceJsonWriter
-
getOutput
public java.lang.String getOutput()getOutput
- Specified by:
getOutputin interfaceJsonWriter- Returns:
- the output when the serialization is over
-