public final class JsonGenerator
extends java.lang.Object
String
s of valid JSON and to stream valid JSON text to a java.io.Writer
.
Instances of this class are immutable, reusable, and thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
JsonGenerator.JsonGeneratorStyle
Styles of output a
JsonGenerator can produce. |
Constructor and Description |
---|
JsonGenerator() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
generate(JsonNode jsonNode)
Generates a JSON representation of the given
JsonNode as a String . |
java.lang.String |
generate(WriteableJsonArray writeableJsonArray)
Generates a JSON representation of the given
WriteableJsonArray as a String . |
java.lang.String |
generate(WriteableJsonNumber writeableJsonNumber)
Generates a JSON representation of the given
WriteableJsonNumber as a String . |
java.lang.String |
generate(WriteableJsonObject writeableJsonObject)
Generates a JSON representation of the given
WriteableJsonObject as a String . |
java.lang.String |
generate(WriteableJsonString writeableJsonString)
Generates a JSON representation of the given
WriteableJsonString as a String . |
void |
generate(java.io.Writer target,
JsonNode jsonNode)
Streams a JSON representation of the given
JsonNode to the given Writer . |
void |
generate(java.io.Writer target,
WriteableJsonArray writeableJsonArray)
Streams a JSON representation of the given
WriteableJsonArray to the given Writer . |
void |
generate(java.io.Writer target,
WriteableJsonNumber writeableJsonNumber)
Streams a JSON representation of the given
WriteableJsonNumber to the given Writer . |
void |
generate(java.io.Writer target,
WriteableJsonObject writeableJsonObject)
Streams a JSON representation of the given
WriteableJsonObject to the given Writer . |
void |
generate(java.io.Writer target,
WriteableJsonString writeableJsonString)
Streams a JSON representation of the given
WriteableJsonString to the given Writer . |
java.lang.String |
generateWithFieldSorting(JsonNode jsonNode)
Generates a JSON representation of the given
JsonNode as a String , outputting fields in lexicographic order. |
void |
generateWithFieldSorting(java.io.Writer target,
JsonNode jsonNode)
Streams a JSON representation of the given
JsonNode to the given Writer , outputting fields in lexicographic order. |
JsonGenerator |
style(JsonGenerator.JsonGeneratorStyle style)
Returns a
JsonGenerator with the given output style. |
public void generate(java.io.Writer target, WriteableJsonArray writeableJsonArray) throws java.io.IOException
WriteableJsonArray
to the given Writer
.target
- the Writer
to output to.writeableJsonArray
- the WriteableJsonArray
to output.java.io.IOException
- if there was a problem writing to the Writer
.public java.lang.String generate(WriteableJsonArray writeableJsonArray) throws java.io.IOException
WriteableJsonArray
as a String
.writeableJsonArray
- the WriteableJsonArray
to output.WriteableJsonArray
as a String
java.io.IOException
- propagated from WriteableJsonArray.writeTo(ArrayWriter)
.public void generate(java.io.Writer target, WriteableJsonObject writeableJsonObject) throws java.io.IOException
WriteableJsonObject
to the given Writer
.target
- the Writer
to output to.writeableJsonObject
- the WriteableJsonObject
to output.java.io.IOException
- if there was a problem writing to the Writer
.public java.lang.String generate(WriteableJsonObject writeableJsonObject) throws java.io.IOException
WriteableJsonObject
as a String
.writeableJsonObject
- the WriteableJsonObject
to output.WriteableJsonObject
as a String
java.io.IOException
- propagated from WriteableJsonObject.writeTo(ObjectWriter)
.public void generate(java.io.Writer target, WriteableJsonString writeableJsonString) throws java.io.IOException
WriteableJsonString
to the given Writer
.target
- the Writer
to output to.writeableJsonString
- the WriteableJsonString
to output.java.io.IOException
- if there was a problem writing to the Writer
.public java.lang.String generate(WriteableJsonString writeableJsonString) throws java.io.IOException
WriteableJsonString
as a String
.writeableJsonString
- the WriteableJsonString
to output.WriteableJsonString
as a String
java.io.IOException
- propagated from WriteableJsonString.writeTo(Writer)
.public void generate(java.io.Writer target, WriteableJsonNumber writeableJsonNumber) throws java.io.IOException
WriteableJsonNumber
to the given Writer
.target
- the Writer
to output to.writeableJsonNumber
- the WriteableJsonNumber
to output.java.io.IOException
- if there was a problem writing to the Writer
.java.lang.IllegalArgumentException
- if the characters written by the WriteableJsonNumber
don't constitute a complete JSON number.public java.lang.String generate(WriteableJsonNumber writeableJsonNumber) throws java.io.IOException
WriteableJsonNumber
as a String
.writeableJsonNumber
- the WriteableJsonNumber
to output.WriteableJsonNumber
as a String
java.io.IOException
- propagated from WriteableJsonNumber.writeTo(Writer)
.java.lang.IllegalArgumentException
- if the characters written by the WriteableJsonNumber
don't constitute a complete JSON number.public void generate(java.io.Writer target, JsonNode jsonNode) throws java.io.IOException
JsonNode
to the given Writer
.target
- the Writer
to output to.jsonNode
- the JsonNode
to output.java.io.IOException
- if there was a problem writing to the Writer
.public java.lang.String generate(JsonNode jsonNode)
JsonNode
as a String
.jsonNode
- the JsonNode
to output.JsonNode
as a String
public void generateWithFieldSorting(java.io.Writer target, JsonNode jsonNode) throws java.io.IOException
JsonNode
to the given Writer
, outputting fields in lexicographic order.
JSON does not mandate a particular ordering for the fields of an object, but for comparing JSON documents it can be convenient for field order to be consistent.
In the event that more than one field with the same name exists in an object, the relative order of those fields is preserved.target
- the Writer
to output to.jsonNode
- the JsonNode
to output.java.io.IOException
- if there was a problem writing to the Writer
.public java.lang.String generateWithFieldSorting(JsonNode jsonNode)
JsonNode
as a String
, outputting fields in lexicographic order.
JSON does not mandate a particular ordering for the fields of an object, but for comparing JSON documents it can be convenient for field order to be consistent.
In the event that more than one field with the same name exists in an object, the relative order of those fields is preserved.jsonNode
- the JsonNode
to output.JsonNode
as a String
public JsonGenerator style(JsonGenerator.JsonGeneratorStyle style)
JsonGenerator
with the given output style.
Defaults to JsonGenerator.JsonGeneratorStyle.PRETTY
.style
- the style of output to produce.JsonGenerator
with the given output style.