Jackson - JsonGenerator Class

Introduction

JsonGenerator is the base class to define class that defines public API for writing JSON content. Instances are created using factory methods of a JsonFactory instance.

Class declaration

Following is the declaration for com.fasterxml.jackson.core.JsonGenerator class:

public abstract class JsonGenerator
   extends Object
      implements Closeable, Flushable, Versioned

Nested Classes

S.N. Class & Description
1 static class JsonGenerator.Feature
Enumeration that defines all togglable features for generators.

Fields

  • protected PrettyPrinter _cfgPrettyPrinter - Object that handles pretty-printing (usually additional white space to make results more human-readable) during output.

Constructors

S.N. Constructor & Description
1 protected JsonGenerator()
Default constructor

Class Methods

S.N. Method & Description
1 protected void _reportError(String msg) - Helper method used for constructing and throwing JsonGenerationException with given base message.
2 protected void _reportUnsupportedOperation()
3 protected void _throwInternal()
4 protected void _writeSimpleObject(Object value)- Helper method to try to call appropriate write method for given untyped Object.
5 boolean canOmitFields() - Introspection method to call to check whether it is ok to omit writing of Object fields or not.
6 boolean canUseSchema(FormatSchema schema) - Method that can be used to verify that given schema can be used with this generator (using setSchema(com.fasterxml.jackson.core.FormatSchema)).
7 boolean canWriteBinaryNatively() - Introspection method that may be called to see if the underlying data format supports "native" binary data; that is, an efficient output of binary content without encoding.
8 boolean canWriteObjectId() - Introspection method that may be called to see if the underlying data format supports some kind of Object Ids natively (many do not; for example, JSON doesn't).
9 boolean canWriteTypeId() - Introspection method that may be called to see if the underlying data format supports some kind of Type Ids natively (many do not; for example, JSON doesn't).
10 abstract void close() - Method called to close this generator, so that no more content can be written.
11 JsonGenerator configure(JsonGenerator.Feature f, boolean state) - Method for enabling or disabling specified feature: check JsonGenerator.Feature for list of available features.
12 void copyCurrentEvent(JsonParser jp) - Method for copying contents of the current event that the given parser instance points to.
13 void copyCurrentStructure(JsonParser jp) - Method for copying contents of the current event and following events that it encloses the given parser instance points to.
14 abstract JsonGenerator disable(JsonGenerator.Feature f) - Method for disabling specified features (check JsonGenerator.Feature for list of features)
15 abstract JsonGenerator enable(JsonGenerator.Feature f) - Method for enabling specified parser features: check JsonGenerator.Feature for list of available features.
16 abstract void flush() - Method called to flush any buffered content to the underlying target (output stream, writer), and to flush the target itself as well.
17 CharacterEscapes getCharacterEscapes() - Method for accessing custom escapes factory uses for JsonGenerators it creates.
18 abstract ObjectCodec getCodec() - Method for accessing the object used for writing Java object as Json content (using method writeObject(java.lang.Object)).
19 abstract int getFeatureMask() - Bulk access method for getting state of all standard JsonGenerator.Features.
20 int getHighestEscapedChar() - Accessor method for testing what is the highest unescaped character configured for this generator.
21 abstract JsonStreamContext getOutputContext()
22 Object getOutputTarget()- Method that can be used to get access to object that is used as target for generated output; this is usually either OutputStream or Writer, depending on what generator was constructed with.
23 PrettyPrinter getPrettyPrinter()- Accessor for checking whether this generator has a configured PrettyPrinter; returns it if so, null if none configured.
24 FormatSchema getSchema() - Method for accessing Schema that this parser uses, if any.
25 abstract boolean isClosed() - Method that can be called to determine whether this generator is closed or not.
26 abstract boolean isEnabled(JsonGenerator.Feature f) - Method for checking whether given feature is enabled.
27 JsonGenerator setCharacterEscapes(CharacterEscapes esc)-Method for defining custom escapes factory uses for JsonGenerators it creates.
28 abstract JsonGenerator setCodec(ObjectCodec oc)- Method that can be called to set or reset the object to use for writing Java objects as JsonContent (using method writeObject(java.lang.Object)).
29 abstract JsonGenerator setFeatureMask(int mask)-Bulk set method for (re)settting states of all standard JsonGenerator.Features
30 JsonGenerator setHighestNonEscapedChar(int charCode) - Method that can be called to request that generator escapes all character codes above specified code point (if positive value); or, to not escape any characters except for ones that must be escaped for the data format (if -1).
31 JsonGenerator setPrettyPrinter(PrettyPrinter pp) - Method for setting a custom pretty printer, which is usually used to add indentation for improved human readability.
32 JsonGenerator setRootValueSeparator(SerializableString sep) - Method that allows overriding String used for separating root-level JSON values (default is single space character)
33 void setSchema(FormatSchema schema) - Method to call to make this generator use specified schema.
33 abstract JsonGenerator useDefaultPrettyPrinter()- Convenience method for enabling pretty-printing using the default pretty printer (DefaultPrettyPrinter).
34 abstract Version version()- Accessor for finding out version of the bundle that provided this generator instance.
35 void writeArrayFieldStart(String fieldName)- Convenience method for outputting a field entry ("member") (that will contain a JSON Array value), and the START_ARRAY marker.
36 abstract void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len)- Method that will output given chunk of binary data as base64 encoded, as a complete String value (surrounded by double quotes).
37 abstract int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) - Method similar to writeBinary(Base64Variant,byte[],int,int), but where input is provided through a stream, allowing for incremental writes without holding the whole input in memory.
38 void writeBinary(byte[] data)- Similar to writeBinary(Base64Variant,byte[],int,int), but assumes default to using the Jackson default Base64 variant (which is Base64Variants.MIME_NO_LINEFEEDS).
39 void writeBinary(byte[] data, int offset, int len) - Similar to writeBinary(Base64Variant,byte[],int,int), but default to using the Jackson default Base64 variant (which is Base64Variants.MIME_NO_LINEFEEDS).
40 int writeBinary(InputStream data, int dataLength) - Similar to writeBinary(Base64Variant,InputStream,int), but assumes default to using the Jackson default Base64 variant (which is Base64Variants.MIME_NO_LINEFEEDS).
41 void writeBinaryField(String fieldName, byte[] data) - Convenience method for outputting a field entry ("member") that contains specified data in base64-encoded form.
42 abstract void writeBoolean(boolean state) - Method for outputting literal Json boolean value (one of Strings 'true' and 'false').
43 void writeBooleanField(String fieldName, boolean value) - Convenience method for outputting a field entry ("member") that has a boolean value.
44 abstract void writeEndArray() - Method for writing closing marker of a JSON Array value (character ']'; plus possible white space decoration if pretty-printing is enabled).
45 abstract void writeEndObject() - Method for writing closing marker of a JSON Object value (character '}'; plus possible white space decoration if pretty-printing is enabled).
46 abstract void writeFieldName(SerializableString name) - Method similar to writeFieldName(String), main difference being that it may perform better as some of processing (such as quoting of certain characters, or encoding into external encoding if supported by generator) can be done just once and reused for later calls.
47 abstract void writeFieldName(String name) - Method for writing a field name (JSON String surrounded by double quotes: syntactically identical to a JSON String value), possibly decorated by white space if pretty-printing is enabled.
48 abstract void writeNull() - Method for outputting literal Json null value.
49 void writeNullField(String fieldName) - Convenience method for outputting a field entry ("member") that has JSON literal value null.
50 abstract void writeNumber(BigDecimal dec) - Method for outputting indicate Json numeric value.
51 abstract void writeNumber(BigInteger v) - Method for outputting given value as Json number.
52 abstract void writeNumber(double d) - Method for outputting indicate Json numeric value.
53 abstract void writeNumber(float f) - Method for outputting indicate Json numeric value.
54 abstract void writeNumber(int v) - Method for outputting given value as Json number.
55 abstract void writeNumber(long v) - Method for outputting given value as Json number.
56 void writeNumber(short v) - Method for outputting given value as Json number.
57 abstract void writeNumber(String encodedValue) - Write method that can be used for custom numeric types that can not be (easily?) converted to "standard" Java number types.
58 void writeNumberField(String fieldName, BigDecimal value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
59 void writeNumberField(String fieldName, double value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
60 void writeNumberField(String fieldName, float value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
61 void writeNumberField(String fieldName, int value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
62 void writeNumberField(String fieldName, long value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
63 abstract void writeObject(Object pojo) - Method for writing given Java object (POJO) as Json.
64 void writeObjectField(String fieldName, Object pojo) - Convenience method for outputting a field entry ("member") that has contents of specific Java object as its value.
65 void writeObjectFieldStart(String fieldName) - Convenience method for outputting a field entry ("member") (that will contain a JSON Object value), and the START_OBJECT marker.
66 void writeObjectId(Object id) - Method that can be called to output so-called native Object Id.
67 void writeObjectRef(Object id) - Method that can be called to output references to native Object Ids.
68 void writeOmittedField(String fieldName) Method called to indicate that a property in this position was skipped.
69 abstract void writeRaw(char c) - Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
70 abstract void writeRaw(char[] text, int offset, int len) - Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
71 void writeRaw(SerializableString raw) - Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
72 abstract void writeRaw(String text) - Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
73 abstract void writeRaw(String text, int offset, int len) - Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
74 abstract void writeRawUTF8String(byte[] text, int offset, int length) - Method similar to writeString(String) but that takes as its input a UTF-8 encoded String that is to be output as-is, without additional escaping (type of which depends on data format; backslashes for JSON).
75 abstract void writeRawValue(char[] text, int offset, int len)
76 abstract void writeRawValue(String text)- Method that will force generator to copy input text verbatim without any modifications, but assuming it must constitute a single legal JSON value (number, string, boolean, null, Array or List).
77 abstract void writeRawValue(String text, int offset, int len)
78 abstract void writeStartArray()- Method for writing starting marker of a JSON Array value (character '['; plus possible white space decoration if pretty-printing is enabled).
79 abstract void writeStartObject() - Method for writing starting marker of a JSON Object value (character '{'; plus possible white space decoration if pretty-printing is enabled).
80 abstract void writeString(char[] text, int offset, int len) - Method for outputting a String value.
81 abstract void writeString(SerializableString text) - Method similar to writeString(String), but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.
82 abstract void writeString(String text) - Method for outputting a String value.
83 void writeStringField(String fieldName, String value) - Convenience method for outputting a field entry ("member") that has a String value.
84 abstract void writeTree(TreeNode rootNode) - Method for writing given JSON tree (expressed as a tree where given JsonNode is the root) using this generator.
85 void writeTypeId(Object id) - Method that can be called to output so-called native Type Id.
86 abstract void writeUTF8String(byte[] text, int offset, int length) - Method similar to writeString(String) but that takes as its input a UTF-8 encoded String which has not been escaped using whatever escaping scheme data format requires (for JSON that is backslash-escaping for control characters and double-quotes; for other formats something else).

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object