-
- All Implemented Interfaces:
-
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public final class JsonStream implements Closeable, Flushable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceJsonStream.Streamable
-
Field Summary
Fields Modifier and Type Field Description private BooleanisLenientprivate BooleanisHtmlSafe
-
Constructor Summary
Constructors Constructor Description JsonStream(Writer out)
-
Method Summary
Modifier and Type Method Description final BooleangetIsLenient()Configure this writer to relax its syntax rules. final UnitsetIsLenient(Boolean isLenient)Configure this writer to relax its syntax rules. final BooleangetIsHtmlSafe()Configure this writer to emit JSON that's safe for direct inclusion in HTML and XML documents. final UnitsetIsHtmlSafe(Boolean isHtmlSafe)Configure this writer to emit JSON that's safe for direct inclusion in HTML and XML documents. final UnitsetIndent(String indent)Sets the indentation string to be repeated for each level of indentation in the encoded document. final JsonStreambeginArray()Begins encoding a new array. final JsonStreamendArray()Ends encoding the current array. final JsonStreambeginObject()Begins encoding a new object. final JsonStreamendObject()Ends encoding the current object. Unitclose()Flushes and closes this writer and the underlying Writer. final JsonStreamname(String name)Encodes the property name. final JsonStreamvalue(String value)Encodes value.final JsonStreamvalue(Boolean value)Encodes value.final JsonStreamvalue(Boolean value)Encodes value.final JsonStreamvalue(Double value)Encodes value.final JsonStreamvalue(Long value)Encodes value.final JsonStreamvalue(Number value)Encodes value.final JsonStreamvalue(Object obj, Boolean shouldRedactKeys)Serialises an arbitrary object as JSON, handling primitive types as well as Collections, Maps, and arrays. final JsonStreamvalue(Object obj)Serialises an arbitrary object as JSON, handling primitive types as well as Collections, Maps, and arrays. final JsonStreamvalue(File file)Writes a File (its content) into the stream final JsonStreamjsonValue(String value)Writes valuedirectly to the writer without quoting or escaping.final JsonStreamnullValue()Encodes null.Unitflush()Ensures all buffered data is written to the underlying Writer and flushes that writer. -
-
Constructor Detail
-
JsonStream
JsonStream(Writer out)
-
-
Method Detail
-
getIsLenient
final Boolean getIsLenient()
Configure this writer to relax its syntax rules. By default, this writer only emits well-formed JSON as specified by RFC 7159. 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 Double.isNaN or Double.isInfinite.
-
setIsLenient
final Unit setIsLenient(Boolean isLenient)
Configure this writer to relax its syntax rules. By default, this writer only emits well-formed JSON as specified by RFC 7159. 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 Double.isNaN or Double.isInfinite.
-
getIsHtmlSafe
final Boolean getIsHtmlSafe()
Configure this writer to emit JSON that's safe for direct inclusion in HTML and XML documents. This escapes the HTML characters
<,>,&and=before writing them to the stream. Without this setting, your XML/HTML encoder should replace these characters with the corresponding escape sequences.
-
setIsHtmlSafe
final Unit setIsHtmlSafe(Boolean isHtmlSafe)
Configure this writer to emit JSON that's safe for direct inclusion in HTML and XML documents. This escapes the HTML characters
<,>,&and=before writing them to the stream. Without this setting, your XML/HTML encoder should replace these characters with the corresponding escape sequences.
-
setIndent
final Unit setIndent(String indent)
Sets the indentation string to be repeated for each level of indentation in the encoded document. If
indent.isEmpty()the encoded document will be compact. Otherwise the encoded document will be more human-readable.- Parameters:
indent- a string containing only whitespace.
-
beginArray
final JsonStream beginArray()
Begins encoding a new array. Each call to this method must be paired with a call to .endArray.
-
endArray
final JsonStream endArray()
Ends encoding the current array.
-
beginObject
final JsonStream beginObject()
Begins encoding a new object. Each call to this method must be paired with a call to .endObject.
-
endObject
final JsonStream endObject()
Ends encoding the current object.
-
name
final JsonStream name(String name)
Encodes the property name.
- Parameters:
name- the name of the forthcoming value.
-
value
final JsonStream value(String value)
Encodes
value.- Parameters:
value- the literal string value, or null to encode a null literal.
-
value
final JsonStream value(Boolean value)
Encodes
value.
-
value
final JsonStream value(Boolean value)
Encodes
value.
-
value
final JsonStream value(Double value)
Encodes
value.- Parameters:
value- a finite value.
-
value
final JsonStream value(Long value)
Encodes
value.
-
value
final JsonStream value(Number value)
Encodes
value.- Parameters:
value- a finite value.
-
value
final JsonStream value(Object obj, Boolean shouldRedactKeys)
Serialises an arbitrary object as JSON, handling primitive types as well as Collections, Maps, and arrays.
-
value
final JsonStream value(Object obj)
Serialises an arbitrary object as JSON, handling primitive types as well as Collections, Maps, and arrays.
-
value
final JsonStream value(File file)
Writes a File (its content) into the stream
-
jsonValue
final JsonStream jsonValue(String value)
Writes
valuedirectly to the writer without quoting or escaping.- Parameters:
value- the literal string value, or null to encode a null literal.
-
nullValue
final JsonStream nullValue()
Encodes
null.
-
-
-
-