Features for configuring low-level JSON writing
Following on/off features are defined in JsonGenerator.Feature: (note: disabled/enabled in parenthesis indicates default state of the feature if no explicit calls are made).
All features can be enabled either for JsonFactory (to determine default state for generators factory creates) and for individual JsonGenerators if not otherwise mentioned below.
- AUTO_CLOSE_TARGET(default: enabled)
Feature that determines whether parser will automatically close underlying output target that is not directly owned by the parser (i.e. one it did not explicitly create). If disabled, application has to separately close the underlying OutputStream and Writer instances passed to generator. If enabled, generator will handle closing, as long as generator itself gets closed by a call to JsonParser.close().
- AUTO_CLOSE_JSON_CONTENT(default: enabled)
Feature that determines what happens when the generator is closed while there are still unmatched JsonToken#START_ARRAY or JsonToken#START_OBJECT entries in content output. If enabled, such Array(s) and/or Object(s) are automatically closed by implicitly writing matching markers; if disabled, nothing specific is done.
- QUOTE_NON_NUMERIC_NUMBERS(default: enabled)
Feature that determines whether "exceptional" (not real number) float/double values are outputted as quoted strings.The values checked are Double.Nan, Double.POSITIVE_INFINITY and Double.NEGATIVE_INIFINTY (and similar Float values). If feature is disabled, these numbers are still output using associated literal values, resulting in non-valid output (one that fully JSON-conformant parsers can not read).
WRITE_NUMBERS_AS_STRINGS(default: disabled) (since 1.3)
FLUSH_PASSED_TO_STREAM(default: enabled) (since 1.7) Feature that determines whether calls to JsonGenerator.flush() will result in matching call to flush() method of underlying output stream or writer.
ESCAPE_NON_ASCII(default: disabled) (since 1.8) Feature that determines whether all characters codes outside of 7-bit ASCII range (code points above 127) are to be escaped, using format-specific escapes (if format uses escaping). This is independent of choice of actual encoding; but typically used when nominal encoding is UTF8 -- with escaping resulting output will be 7-bit ASCII compliant, which is useful in some cases.
Support for writing non-standard "JSON"
By default Jackson conforms strictly to JSON specification. But since there are unfortunate cases where it may be necessary to produce non-standard JSON(-like) content, there exists limited number of features for producing non-standard content: