Package org.dominokit.jacksonapt.stream
Interface JsonWriter
- All Known Implementing Classes:
DefaultJsonWriter,FastJsonWriter
public interface JsonWriter
JsonWriter interface.
- Version:
- $Id: $
- Author:
- nicolasmorel
-
Method Summary
Modifier and Type Method Description JsonWriterbeginArray()Begins encoding a new array.JsonWriterbeginObject()Begins encoding a new object.JsonWritercancelName()cancelNamevoidclose()Flushes and closes this writer and the underlyingStringBuilder.JsonWriterendArray()Ends encoding the current array.JsonWriterendObject()Ends encoding the current object.voidflush()Ensures all buffered data is written to the underlyingStringBuilderand flushes that writer.java.lang.StringgetOutput()getOutputbooleangetSerializeNulls()getSerializeNullsJsonWritername(java.lang.String name)Encodes the property name.JsonWriternullValue()Encodesnull.JsonWriterrawValue(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.JsonWriterunescapeName(java.lang.String name)Encodes the property name without escaping it.JsonWriterunescapeValue(java.lang.String value)Encodesvaluewithout escaping it.JsonWritervalue(boolean value)Encodesvalue.JsonWritervalue(double value)Encodesvalue.JsonWritervalue(long value)Encodesvalue.JsonWritervalue(java.lang.Number value)Encodesvalue.JsonWritervalue(java.lang.String value)Encodesvalue.
-
Method Details
-
setIndent
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.- Parameters:
indent- a string containing only whitespace.
-
setLenient
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.
- Parameters:
lenient- a boolean.
-
setSerializeNulls
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.- Parameters:
serializeNulls- a boolean.
-
getSerializeNulls
boolean getSerializeNulls()getSerializeNulls
- Returns:
- a boolean.
-
beginArray
JsonWriter beginArray()Begins encoding a new array. Each call to this method must be paired with a call toendArray().- Returns:
- this writer.
-
endArray
JsonWriter endArray()Ends encoding the current array.- Returns:
- this writer.
-
beginObject
JsonWriter beginObject()Begins encoding a new object. Each call to this method must be paired with a call toendObject().- Returns:
- this writer.
-
endObject
JsonWriter endObject()Ends encoding the current object.- Returns:
- this writer.
-
name
Encodes the property name.- Parameters:
name- the name of the forthcoming value. May not be null.- Returns:
- this writer.
-
unescapeName
Encodes the property name without escaping it.- Parameters:
name- the name of the forthcoming value. May not be null.- Returns:
- this writer.
-
value
Encodesvalue.- Parameters:
value- the literal string value, or null to encode a null literal.- Returns:
- this writer.
-
unescapeValue
Encodesvaluewithout escaping it.- Parameters:
value- the literal string value, or null to encode a null literal.- Returns:
- this writer.
-
nullValue
JsonWriter nullValue()Encodesnull.- Returns:
- this writer.
-
cancelName
JsonWriter cancelName()cancelName
- Returns:
- a
JsonWriterobject.
-
value
Encodesvalue.- Parameters:
value- a boolean.- Returns:
- this writer.
-
value
Encodesvalue.- Parameters:
value- a finite value. May not beNaNsorinfinities.- Returns:
- this writer.
-
value
Encodesvalue.- Parameters:
value- a long.- Returns:
- this writer.
-
value
Encodesvalue.- Parameters:
value- a finite value. May not beNaNsorinfinities.- Returns:
- this writer.
-
rawValue
Encodesvalue.toString() as is.- Parameters:
value- a value .- Returns:
- this writer.
-
flush
void flush()Ensures all buffered data is written to the underlyingStringBuilderand flushes that writer. -
close
void close()Flushes and closes this writer and the underlyingStringBuilder. -
getOutput
java.lang.String getOutput()getOutput
- Returns:
- the output when the serialization is over
-