From f0aa287907feee6dd71c8034e0621539bafa549a Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 29 Nov 2024 19:30:53 -0800 Subject: [PATCH] Implement #512: refactory YAML read/write features --- release-notes/VERSION | 2 + .../dataformat/toml/TomlReadFeature.java | 7 +- .../dataformat/toml/TomlWriteFeature.java | 7 +- .../jackson/dataformat/yaml/YAMLFactory.java | 20 +- .../dataformat/yaml/YAMLFactoryBuilder.java | 40 ++-- .../dataformat/yaml/YAMLGenerator.java | 176 ++---------------- .../jackson/dataformat/yaml/YAMLMapper.java | 20 +- .../jackson/dataformat/yaml/YAMLParser.java | 59 +----- .../dataformat/yaml/YAMLReadFeature.java | 49 +++++ .../dataformat/yaml/YAMLWriteFeature.java | 154 +++++++++++++++ .../deser/NullFromEmptyString130Test.java | 6 +- .../yaml/failing/SimpleGeneration366Test.java | 8 +- .../dataformat/yaml/misc/ObjectIdTest.java | 4 +- .../yaml/ser/CustomNodeStyleTest.java | 6 +- .../yaml/ser/CustomStringQuoting229Test.java | 6 +- .../yaml/ser/GeneratorFeature175Test.java | 8 +- .../yaml/ser/GeneratorFeature34Test.java | 4 +- .../yaml/ser/GeneratorFeatureTest.java | 6 +- .../yaml/ser/GeneratorWithMinimizeTest.java | 18 +- .../yaml/ser/GeneratorWithSplitLinesTest.java | 4 +- .../yaml/ser/SimpleGeneration215Test.java | 6 +- .../yaml/ser/SimpleGenerationTest.java | 16 +- .../dataformat/yaml/type/TypeIdTest.java | 4 +- 23 files changed, 317 insertions(+), 313 deletions(-) create mode 100644 yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLReadFeature.java create mode 100644 yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLWriteFeature.java diff --git a/release-notes/VERSION b/release-notes/VERSION index b123d9eb5..49eb2d36b 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -22,6 +22,8 @@ implementations) (suggested by @SebastianSolidwork) #510: JSTEP-8: rename `CsvParser.Feature` as `CsvReadFeature`, `CsvGenerator.Feature` as `CsvWriteFeature` +#512: JSTEP-8: rename `YAMLParser.Feature` as `YAMLReadFeature`, + `YAMLGenerator.Feature` as `YAMLWriteFeature` - Add `XxxMapper.shared()` methods for getting globally shared default instances CSV: diff --git a/toml/src/main/java/tools/jackson/dataformat/toml/TomlReadFeature.java b/toml/src/main/java/tools/jackson/dataformat/toml/TomlReadFeature.java index 8c7619ed6..5a4afb5f8 100644 --- a/toml/src/main/java/tools/jackson/dataformat/toml/TomlReadFeature.java +++ b/toml/src/main/java/tools/jackson/dataformat/toml/TomlReadFeature.java @@ -6,7 +6,8 @@ * Enumeration that defines all togglable features for TOML parsers. */ public enum TomlReadFeature - implements FormatFeature { + implements FormatFeature +{ /** * TOML has special syntax for time types corresponding to {@link java.time.LocalDate}, {@link java.time.LocalTime}, * {@link java.time.LocalDateTime} and {@link java.time.OffsetDateTime}. By default, the TOML parser just returns @@ -17,8 +18,8 @@ public enum TomlReadFeature */ PARSE_JAVA_TIME(false); - final boolean _defaultState; - final int _mask; + private final boolean _defaultState; + private final int _mask; // Method that calculates bit set (flags) of all features that // are enabled by default. diff --git a/toml/src/main/java/tools/jackson/dataformat/toml/TomlWriteFeature.java b/toml/src/main/java/tools/jackson/dataformat/toml/TomlWriteFeature.java index 2c6a48242..df4209b3b 100644 --- a/toml/src/main/java/tools/jackson/dataformat/toml/TomlWriteFeature.java +++ b/toml/src/main/java/tools/jackson/dataformat/toml/TomlWriteFeature.java @@ -6,7 +6,8 @@ /** * Enumeration that defines all togglable features for TOML generators. */ -public enum TomlWriteFeature implements FormatFeature { +public enum TomlWriteFeature implements FormatFeature +{ /** * The TOML spec does not allow null values. We instead write an empty string when * {@link JsonGenerator#writeNull()} by default. @@ -20,8 +21,8 @@ public enum TomlWriteFeature implements FormatFeature { */ static final int INTERNAL_PROHIBIT_INTERNAL_BUFFER_ALLOCATE = 0x80000000; - final boolean _defaultState; - final int _mask; + private final boolean _defaultState; + private final int _mask; // Method that calculates bit set (flags) of all features that // are enabled by default. diff --git a/yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLFactory.java b/yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLFactory.java index 00da38c9b..9ee1193df 100644 --- a/yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLFactory.java +++ b/yaml/src/main/java/tools/jackson/dataformat/yaml/YAMLFactory.java @@ -29,13 +29,13 @@ public class YAMLFactory * Bitfield (set of flags) of all generator features that are enabled * by default. */ - protected final static int DEFAULT_YAML_PARSER_FEATURE_FLAGS = YAMLParser.Feature.collectDefaults(); + protected final static int DEFAULT_YAML_PARSER_FEATURE_FLAGS = YAMLReadFeature.collectDefaults(); /** * Bitfield (set of flags) of all generator features that are enabled * by default. */ - protected final static int DEFAULT_YAML_GENERATOR_FEATURE_FLAGS = YAMLGenerator.Feature.collectDefaults(); + protected final static int DEFAULT_YAML_GENERATOR_FEATURE_FLAGS = YAMLWriteFeature.collectDefaults(); /* /********************************************************************** @@ -64,9 +64,9 @@ public class YAMLFactory /** * Configuration for underlying generator to follow, if specified; * left as {@code null} for backwards compatibility (which means - * the dumper options are derived based on {@link YAMLGenerator.Feature}s). + * the dumper options are derived based on {@link YAMLWriteFeature}s). *

- * These {@link YAMLGenerator.Feature}s are ignored if you provide your own DumperOptions: + * These {@link YAMLWriteFeature}s are ignored if you provide your own DumperOptions: *