Enum JsonGenerator.Feature
- All Implemented Interfaces:
Serializable
,Comparable<JsonGenerator.Feature>
,java.lang.constant.Constable
- Enclosing class:
- JsonGenerator
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionFeature that determines what happens when the generator is closed while there are still unmatchedJsonToken.START_ARRAY
orJsonToken.START_OBJECT
entries in output content.Feature that determines whether generator will automatically close underlying output target that is NOT owned by the generator.Deprecated.Feature that specifies that calls toJsonGenerator.flush()
will cause matchingflush()
to underlyingOutputStream
orWriter
; if disabled this will not be done.Feature that determines what to do if the underlying data format requires knowledge of all properties to output, and if no definition is found for a property that caller tries to write.Deprecated.Since 2.10 useJsonWriteFeature.QUOTE_FIELD_NAMES
insteadDeprecated.Since 2.10 useJsonWriteFeature.WRITE_NAN_AS_STRINGS
insteadFeature that determines whetherJsonGenerator
will explicitly check that no duplicate JSON Object field names are written.Deprecated.UseStreamWriteFeature.USE_FAST_DOUBLE_WRITER
insteadFeature that determines whetherBigDecimal
entries are serialized usingBigDecimal.toPlainString()
to prevent values to be written using scientific notation.Deprecated.UseJsonWriteFeature.WRITE_HEX_UPPER_CASE
insteadDeprecated.Since 2.10 useJsonWriteFeature.WRITE_NUMBERS_AS_STRINGS
instead -
Method Summary
Modifier and TypeMethodDescriptionstatic int
Method that calculates bit set (flags) of all features that are enabled by default.boolean
boolean
enabledIn
(int flags) int
getMask()
static JsonGenerator.Feature
Returns the enum constant of this type with the specified name.static JsonGenerator.Feature[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
AUTO_CLOSE_TARGET
Feature that determines whether generator will automatically close underlying output target that is NOT owned by the generator. If disabled, calling application has to separately close the underlyingOutputStream
andWriter
instances used to create the generator. If enabled, generator will handle closing, as long as generator itself gets closed: this happens when end-of-input is encountered, or generator is closed by a call toJsonGenerator.close()
.Feature is enabled by default.
-
AUTO_CLOSE_JSON_CONTENT
Feature that determines what happens when the generator is closed while there are still unmatchedJsonToken.START_ARRAY
orJsonToken.START_OBJECT
entries in output content. If enabled, such Array(s) and/or Object(s) are automatically closed; if disabled, nothing specific is done.Feature is enabled by default.
-
FLUSH_PASSED_TO_STREAM
Feature that specifies that calls toJsonGenerator.flush()
will cause matchingflush()
to underlyingOutputStream
orWriter
; if disabled this will not be done. Main reason to disable this feature is to prevent flushing at generator level, if it is not possible to prevent method being called by other code (likeObjectMapper
or third party libraries).Feature is enabled by default.
-
QUOTE_FIELD_NAMES
Deprecated.Since 2.10 useJsonWriteFeature.QUOTE_FIELD_NAMES
insteadFeature that determines whether JSON Object field names are quoted using double-quotes, as specified by JSON specification or not. Ability to disable quoting was added to support use cases where they are not usually expected, which most commonly occurs when used straight from Javascript.Feature is enabled by default (since it is required by JSON specification).
-
QUOTE_NON_NUMERIC_NUMBERS
Deprecated.Since 2.10 useJsonWriteFeature.WRITE_NAN_AS_STRINGS
insteadFeature that determines whether "exceptional" (not real number) float/double values are output as quoted strings. The values checked are Double.Nan, Double.POSITIVE_INFINITY and Double.NEGATIVE_INIFINTY (and associated Float values). If feature is disabled, these numbers are still output using associated literal values, resulting in non-conformant output.Feature is enabled by default.
-
ESCAPE_NON_ASCII
Deprecated.Since 2.10 useJsonWriteFeature.ESCAPE_NON_ASCII
insteadFeature that specifies that all characters beyond 7-bit ASCII range (i.e. code points of 128 and above) need to be output using format-specific escapes (for JSON, backslash escapes), if format uses escaping mechanisms (which is generally true for textual formats but not for binary formats).Note that this setting may not necessarily make sense for all data formats (for example, binary formats typically do not use any escaping mechanisms; and some textual formats do not have general-purpose escaping); if so, settings is simply ignored. Put another way, effects of this feature are data-format specific.
Feature is disabled by default.
-
WRITE_NUMBERS_AS_STRINGS
Deprecated.Since 2.10 useJsonWriteFeature.WRITE_NUMBERS_AS_STRINGS
insteadFeature that forces all Java numbers to be written as Strings, even if the underlying data format has non-textual representation (which is the case for JSON as well as all binary formats). Default state is 'false', meaning that Java numbers are to be serialized using basic numeric serialization (as JSON numbers, integral or floating point, for example). If enabled, all such numeric values are instead written out as textual values (which for JSON means quoted in double-quotes).One use case is to avoid problems with Javascript limitations: since Javascript standard specifies that all number handling should be done using 64-bit IEEE 754 floating point values, result being that some 64-bit integer values can not be accurately represent (as mantissa is only 51 bit wide).
Feature is disabled by default.
-
WRITE_BIGDECIMAL_AS_PLAIN
Feature that determines whetherBigDecimal
entries are serialized usingBigDecimal.toPlainString()
to prevent values to be written using scientific notation.NOTE: only affects generators that serialize
BigDecimal
s using textual representation (textual formats but potentially some binary formats).Feature is disabled by default, so default output mode is used; this generally depends on how
BigDecimal
has been created.- Since:
- 2.3
-
STRICT_DUPLICATE_DETECTION
Feature that determines whetherJsonGenerator
will explicitly check that no duplicate JSON Object field names are written. If enabled, generator will check all names within context and report duplicates by throwing aJsonGenerationException
; if disabled, no such checking will be done. Assumption in latter case is that caller takes care of not trying to write duplicate names.Note that enabling this feature will incur performance overhead due to having to store and check additional information.
Feature is disabled by default.
- Since:
- 2.3
-
IGNORE_UNKNOWN
Feature that determines what to do if the underlying data format requires knowledge of all properties to output, and if no definition is found for a property that caller tries to write. If enabled, such properties will be quietly ignored; if disabled, aJsonProcessingException
will be thrown to indicate the problem. Typically most textual data formats do NOT require schema information (although some do, such as CSV), whereas many binary data formats do require definitions (such as Avro, protobuf), although not all (Smile, CBOR, BSON and MessagePack do not).Note that support for this feature is implemented by individual data format module, if (and only if) it makes sense for the format in question. For JSON, for example, this feature has no effect as properties need not be pre-defined.
Feature is disabled by default, meaning that if the underlying data format requires knowledge of all properties to output, attempts to write an unknown property will result in a
JsonProcessingException
- Since:
- 2.5
-
USE_FAST_DOUBLE_WRITER
Deprecated.UseStreamWriteFeature.USE_FAST_DOUBLE_WRITER
insteadAlias forStreamWriteFeature.USE_FAST_DOUBLE_WRITER
instead- Since:
- 2.14
-
WRITE_HEX_UPPER_CASE
Deprecated.UseJsonWriteFeature.WRITE_HEX_UPPER_CASE
insteadFeature that specifies that hex values are encoded with capital letters.Can be disabled to have a better possibility to compare between other Json writer libraries, such as JSON.stringify from Javascript.
Feature is enabled by default.
- Since:
- 2.14
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
collectDefaults
public static int collectDefaults()Method that calculates bit set (flags) of all features that are enabled by default.- Returns:
- Bit field of the features that are enabled by default
-
enabledByDefault
public boolean enabledByDefault() -
enabledIn
public boolean enabledIn(int flags) -
getMask
public int getMask()
-
JsonWriteFeature.ESCAPE_NON_ASCII
instead