Jackson - JsonGenerator Class


Advertisements

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
1static 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
1protected JsonGenerator()
Default constructor

Class Methods

S.N.Method & Description
1protected void _reportError(String msg) - Helper method used for constructing and throwing JsonGenerationException with given base message.
2protected void _reportUnsupportedOperation()
3protected void _throwInternal()
4protected void _writeSimpleObject(Object value)- Helper method to try to call appropriate write method for given untyped Object.
5boolean canOmitFields() - Introspection method to call to check whether it is ok to omit writing of Object fields or not.
6boolean 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)).
7boolean 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.
8boolean 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).
9boolean 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).
10abstract void close() - Method called to close this generator, so that no more content can be written.
11JsonGenerator configure(JsonGenerator.Feature f, boolean state) - Method for enabling or disabling specified feature: check JsonGenerator.Feature for list of available features.
12void copyCurrentEvent(JsonParser jp) - Method for copying contents of the current event that the given parser instance points to.
13void copyCurrentStructure(JsonParser jp) - Method for copying contents of the current event and following events that it encloses the given parser instance points to.
14abstract JsonGenerator disable(JsonGenerator.Feature f) - Method for disabling specified features (check JsonGenerator.Feature for list of features)
15abstract JsonGenerator enable(JsonGenerator.Feature f) - Method for enabling specified parser features: check JsonGenerator.Feature for list of available features.
16abstract void flush() - Method called to flush any buffered content to the underlying target (output stream, writer), and to flush the target itself as well.
17CharacterEscapes getCharacterEscapes() - Method for accessing custom escapes factory uses for JsonGenerators it creates.
18abstract ObjectCodec getCodec() - Method for accessing the object used for writing Java object as Json content (using method writeObject(java.lang.Object)).
19abstract int getFeatureMask() - Bulk access method for getting state of all standard JsonGenerator.Features.
20int getHighestEscapedChar() - Accessor method for testing what is the highest unescaped character configured for this generator.
21abstract JsonStreamContext getOutputContext()
22Object 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.
23PrettyPrinter getPrettyPrinter()- Accessor for checking whether this generator has a configured PrettyPrinter; returns it if so, null if none configured.
24FormatSchema getSchema() - Method for accessing Schema that this parser uses, if any.
25abstract boolean isClosed() - Method that can be called to determine whether this generator is closed or not.
26abstract boolean isEnabled(JsonGenerator.Feature f) - Method for checking whether given feature is enabled.
27JsonGenerator setCharacterEscapes(CharacterEscapes esc)-Method for defining custom escapes factory uses for JsonGenerators it creates.
28abstract 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)).
29abstract JsonGenerator setFeatureMask(int mask)-Bulk set method for (re)settting states of all standard JsonGenerator.Features
30JsonGenerator 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).
31JsonGenerator setPrettyPrinter(PrettyPrinter pp) - Method for setting a custom pretty printer, which is usually used to add indentation for improved human readability.
32JsonGenerator setRootValueSeparator(SerializableString sep) - Method that allows overriding String used for separating root-level JSON values (default is single space character)
33void setSchema(FormatSchema schema) - Method to call to make this generator use specified schema.
33abstract JsonGenerator useDefaultPrettyPrinter()- Convenience method for enabling pretty-printing using the default pretty printer (DefaultPrettyPrinter).
34abstract Version version()- Accessor for finding out version of the bundle that provided this generator instance.
35void writeArrayFieldStart(String fieldName)- Convenience method for outputting a field entry ("member") (that will contain a JSON Array value), and the START_ARRAY marker.
36abstract 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).
37abstract 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.
38void 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).
39void 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).
40int 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).
41void writeBinaryField(String fieldName, byte[] data) - Convenience method for outputting a field entry ("member") that contains specified data in base64-encoded form.
42abstract void writeBoolean(boolean state) - Method for outputting literal Json boolean value (one of Strings 'true' and 'false').
43void writeBooleanField(String fieldName, boolean value) - Convenience method for outputting a field entry ("member") that has a boolean value.
44abstract void writeEndArray() - Method for writing closing marker of a JSON Array value (character ']'; plus possible white space decoration if pretty-printing is enabled).
45abstract void writeEndObject() - Method for writing closing marker of a JSON Object value (character '}'; plus possible white space decoration if pretty-printing is enabled).
46abstract 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.
47abstract 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.
48abstract void writeNull() - Method for outputting literal Json null value.
49void writeNullField(String fieldName) - Convenience method for outputting a field entry ("member") that has JSON literal value null.
50abstract void writeNumber(BigDecimal dec) - Method for outputting indicate Json numeric value.
51abstract void writeNumber(BigInteger v) - Method for outputting given value as Json number.
52abstract void writeNumber(double d) - Method for outputting indicate Json numeric value.
53abstract void writeNumber(float f) - Method for outputting indicate Json numeric value.
54abstract void writeNumber(int v) - Method for outputting given value as Json number.
55abstract void writeNumber(long v) - Method for outputting given value as Json number.
56void writeNumber(short v) - Method for outputting given value as Json number.
57abstract 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.
58void writeNumberField(String fieldName, BigDecimal value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
59void writeNumberField(String fieldName, double value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
60void writeNumberField(String fieldName, float value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
61void writeNumberField(String fieldName, int value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
62void writeNumberField(String fieldName, long value) - Convenience method for outputting a field entry ("member") that has the specified numeric value.
63abstract void writeObject(Object pojo) - Method for writing given Java object (POJO) as Json.
64void writeObjectField(String fieldName, Object pojo) - Convenience method for outputting a field entry ("member") that has contents of specific Java object as its value.
65void writeObjectFieldStart(String fieldName) - Convenience method for outputting a field entry ("member") (that will contain a JSON Object value), and the START_OBJECT marker.
66void writeObjectId(Object id) - Method that can be called to output so-called native Object Id.
67void writeObjectRef(Object id) - Method that can be called to output references to native Object Ids.
68void writeOmittedField(String fieldName) Method called to indicate that a property in this position was skipped.
69abstract 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).
70abstract 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).
71void 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).
72abstract 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).
73abstract 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).
74abstract 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).
75abstract void writeRawValue(char[] text, int offset, int len)
76abstract 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).
77abstract void writeRawValue(String text, int offset, int len)
78abstract void writeStartArray()- Method for writing starting marker of a JSON Array value (character '['; plus possible white space decoration if pretty-printing is enabled).
79abstract void writeStartObject() - Method for writing starting marker of a JSON Object value (character '{'; plus possible white space decoration if pretty-printing is enabled).
80abstract void writeString(char[] text, int offset, int len) - Method for outputting a String value.
81abstract 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.
82abstract void writeString(String text) - Method for outputting a String value.
83void writeStringField(String fieldName, String value) - Convenience method for outputting a field entry ("member") that has a String value.
84abstract void writeTree(TreeNode rootNode) - Method for writing given JSON tree (expressed as a tree where given JsonNode is the root) using this generator.
85void writeTypeId(Object id) - Method that can be called to output so-called native Type Id.
86abstract 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

Advertisements