From a4c2b7471fbf7cb405774c35fecb0ff1262d9039 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 29 Nov 2024 19:18:58 -0800 Subject: [PATCH] Implement #510: refactoring of CSV read/write Features --- .../dataformat/csv/CsvCharacterEscapes.java | 5 +- .../jackson/dataformat/csv/CsvFactory.java | 16 +- .../dataformat/csv/CsvFactoryBuilder.java | 28 +-- .../jackson/dataformat/csv/CsvGenerator.java | 138 +----------- .../jackson/dataformat/csv/CsvMapper.java | 20 +- .../jackson/dataformat/csv/CsvParser.java | 212 ++---------------- .../dataformat/csv/CsvReadFeature.java | 163 ++++++++++++++ .../dataformat/csv/CsvWriteFeature.java | 129 +++++++++++ .../dataformat/csv/impl/CsvDecoder.java | 9 +- .../dataformat/csv/impl/CsvEncoder.java | 19 +- .../csv/deser/BlogPost2021AprilTest.java | 6 +- .../csv/deser/CSVBigStringsTest.java | 8 +- .../dataformat/csv/deser/CommentsTest.java | 18 +- .../csv/deser/EmptyStringAsNullTest.java | 8 +- .../deser/EmptyUnquotedStringAsNullTest.java | 12 +- .../csv/deser/IgnoreUnmappableTest.java | 4 +- .../csv/deser/MissingColumns285Test.java | 2 +- .../csv/deser/MissingColumnsTest.java | 4 +- .../dataformat/csv/deser/NullReadTest.java | 2 +- .../csv/deser/ParserLocation483Test.java | 4 +- .../csv/deser/ParserTrimSpacesTest.java | 8 +- .../csv/deser/ReadSequencesTest.java | 10 +- .../csv/deser/SequenceRecoveryTest.java | 2 +- .../csv/deser/SkipEmptyLines15Test.java | 24 +- .../csv/deser/SkipEmptyLines191Test.java | 4 +- .../csv/deser/TestParserEscapes.java | 8 +- .../csv/deser/TestParserNoSchema.java | 14 +- .../csv/deser/TestParserQuotes.java | 8 +- .../csv/deser/TestParserStrictQuoting.java | 4 +- .../csv/deser/TestParserWithHeader.java | 8 +- .../csv/deser/TrailingCommaCSVTest.java | 6 +- .../failing/MappingIteratorEnd119Test.java | 2 +- .../csv/filter/StreamingDecoratorsTest.java | 4 +- .../csv/ser/CSVGeneratorQuotingTest.java | 16 +- .../dataformat/csv/ser/CSVGeneratorTest.java | 34 +-- .../csv/ser/MultipleWritesTest.java | 5 +- .../csv/ser/TestWriterWithMissingValues.java | 4 +- release-notes/VERSION | 2 + 38 files changed, 481 insertions(+), 489 deletions(-) create mode 100644 csv/src/main/java/tools/jackson/dataformat/csv/CsvReadFeature.java create mode 100644 csv/src/main/java/tools/jackson/dataformat/csv/CsvWriteFeature.java diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvCharacterEscapes.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvCharacterEscapes.java index 9870ec9a5..28199bfee 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/CsvCharacterEscapes.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvCharacterEscapes.java @@ -3,7 +3,6 @@ import tools.jackson.core.SerializableString; import tools.jackson.core.io.CharTypes; import tools.jackson.core.io.CharacterEscapes; -import tools.jackson.dataformat.csv.CsvGenerator.Feature; /** * Character escapes for CSV. There are multiple types of escapes. @@ -81,8 +80,8 @@ public static CsvCharacterEscapes controlQuoteEscapesInstance() public static CsvCharacterEscapes fromCsvFeatures(int csvFeatures) { int idx = 0; - idx |= CsvGenerator.Feature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR.enabledIn(csvFeatures) ? 1 : 0; - idx |= Feature.ESCAPE_CONTROL_CHARS_WITH_ESCAPE_CHAR.enabledIn(csvFeatures) ? 2 : 0; + idx |= CsvWriteFeature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR.enabledIn(csvFeatures) ? 1 : 0; + idx |= CsvWriteFeature.ESCAPE_CONTROL_CHARS_WITH_ESCAPE_CHAR.enabledIn(csvFeatures) ? 2 : 0; return sEscapes[idx]; } diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactory.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactory.java index 132c53d42..c2163148e 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactory.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactory.java @@ -25,13 +25,13 @@ public class CsvFactory * Bitfield (set of flags) of all parser features that are enabled * by default. */ - protected final static int DEFAULT_CSV_PARSER_FEATURE_FLAGS = CsvParser.Feature.collectDefaults(); + protected final static int DEFAULT_CSV_PARSER_FEATURE_FLAGS = CsvReadFeature.collectDefaults(); /** * Bitfield (set of flags) of all generator features that are enabled * by default. */ - protected final static int DEFAULT_CSV_GENERATOR_FEATURE_FLAGS = CsvGenerator.Feature.collectDefaults(); + protected final static int DEFAULT_CSV_GENERATOR_FEATURE_FLAGS = CsvWriteFeature.collectDefaults(); // could make it use Platform default too but... protected final static char[] DEFAULT_LF = { '\n' }; @@ -172,13 +172,13 @@ public boolean canUseSchema(FormatSchema schema) { } @Override - public Class getFormatReadFeatureType() { - return CsvParser.Feature.class; + public Class getFormatReadFeatureType() { + return CsvReadFeature.class; } @Override - public Class getFormatWriteFeatureType() { - return CsvGenerator.Feature.class; + public Class getFormatWriteFeatureType() { + return CsvWriteFeature.class; } @Override @@ -190,14 +190,14 @@ public Class getFormatWriteFeatureType() { /** * Checked whether specified parser feature is enabled. */ - public final boolean isEnabled(CsvParser.Feature f) { + public final boolean isEnabled(CsvReadFeature f) { return (_formatReadFeatures & f.getMask()) != 0; } /** * Check whether specified generator feature is enabled. */ - public boolean isEnabled(CsvGenerator.Feature f) { + public boolean isEnabled(CsvWriteFeature f) { return (_formatWriteFeatures & f.getMask()) != 0; } diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactoryBuilder.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactoryBuilder.java index 96da15607..930a4e276 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactoryBuilder.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvFactoryBuilder.java @@ -48,65 +48,65 @@ public CsvFactory build() { // // // Parser features - public CsvFactoryBuilder enable(CsvParser.Feature f) { + public CsvFactoryBuilder enable(CsvReadFeature f) { _formatReadFeatures |= f.getMask(); return _this(); } - public CsvFactoryBuilder enable(CsvParser.Feature first, CsvParser.Feature... other) { + public CsvFactoryBuilder enable(CsvReadFeature first, CsvReadFeature... other) { _formatReadFeatures |= first.getMask(); - for (CsvParser.Feature f : other) { + for (CsvReadFeature f : other) { _formatReadFeatures |= f.getMask(); } return _this(); } - public CsvFactoryBuilder disable(CsvParser.Feature f) { + public CsvFactoryBuilder disable(CsvReadFeature f) { _formatReadFeatures &= ~f.getMask(); return _this(); } - public CsvFactoryBuilder disable(CsvParser.Feature first, CsvParser.Feature... other) { + public CsvFactoryBuilder disable(CsvReadFeature first, CsvReadFeature... other) { _formatReadFeatures &= ~first.getMask(); - for (CsvParser.Feature f : other) { + for (CsvReadFeature f : other) { _formatReadFeatures &= ~f.getMask(); } return _this(); } - public CsvFactoryBuilder configure(CsvParser.Feature f, boolean state) { + public CsvFactoryBuilder configure(CsvReadFeature f, boolean state) { return state ? enable(f) : disable(f); } // // // Generator features - public CsvFactoryBuilder enable(CsvGenerator.Feature f) { + public CsvFactoryBuilder enable(CsvWriteFeature f) { _formatWriteFeatures |= f.getMask(); return _this(); } - public CsvFactoryBuilder enable(CsvGenerator.Feature first, CsvGenerator.Feature... other) { + public CsvFactoryBuilder enable(CsvWriteFeature first, CsvWriteFeature... other) { _formatWriteFeatures |= first.getMask(); - for (CsvGenerator.Feature f : other) { + for (CsvWriteFeature f : other) { _formatWriteFeatures |= f.getMask(); } return _this(); } - public CsvFactoryBuilder disable(CsvGenerator.Feature f) { + public CsvFactoryBuilder disable(CsvWriteFeature f) { _formatWriteFeatures &= ~f.getMask(); return _this(); } - public CsvFactoryBuilder disable(CsvGenerator.Feature first, CsvGenerator.Feature... other) { + public CsvFactoryBuilder disable(CsvWriteFeature first, CsvWriteFeature... other) { _formatWriteFeatures &= ~first.getMask(); - for (CsvGenerator.Feature f : other) { + for (CsvWriteFeature f : other) { _formatWriteFeatures &= ~f.getMask(); } return _this(); } - public CsvFactoryBuilder configure(CsvGenerator.Feature f, boolean state) { + public CsvFactoryBuilder configure(CsvWriteFeature f, boolean state) { return state ? enable(f) : disable(f); } diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvGenerator.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvGenerator.java index a7a0fbe5d..6963d7860 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/CsvGenerator.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvGenerator.java @@ -17,140 +17,6 @@ public class CsvGenerator extends GeneratorBase { - /** - * Enumeration that defines all togglable features for CSV writers - * (if any: currently none) - */ - public enum Feature - implements FormatFeature - { - /** - * Feature that determines how much work is done before determining that - * a column value requires quoting: when set as true, full - * check is made to only use quoting when it is strictly necessary; - * but when false, a faster but more conservative check - * is made, and possibly quoting is used for values that might not need it. - * Trade-offs is basically between optimal/minimal quoting (true), and - * faster handling (false). - * Faster check involves only checking first N characters of value, as well - * as possible looser checks. - *

- * Note, however, that regardless setting, all values that need to be quoted - * will be: it is just that when set to false, other values may - * also be quoted (to avoid having to do more expensive checks). - *

- * Default value is false for "loose" (approximate, conservative) - * checking. - */ - STRICT_CHECK_FOR_QUOTING(false), - - /** - * Feature that determines whether columns without matching value may be omitted, - * when they are the last values of the row. - * If true, values and separators between values may be omitted, to slightly reduce - * length of the row; if false, separators need to stay in place and values - * are indicated by empty Strings. - */ - OMIT_MISSING_TAIL_COLUMNS(false), - - /** - * Feature that determines whether values written as Strings (from java.lang.String - * valued POJO properties) should be forced to be quoted, regardless of whether they - * actually need this. - * Note that this feature has precedence over {@link #STRICT_CHECK_FOR_QUOTING}, when - * both would be applicable. -<<<<<<< HEAD:csv/src/main/java/tools/jackson/dataformat/csv/CsvGenerator.java -======= - * Note that this setting does NOT affect quoting of typed values like {@code Number}s - * or {@code Boolean}s. - * - * @since 2.5 ->>>>>>> 2.16:csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvGenerator.java - */ - ALWAYS_QUOTE_STRINGS(false), - - /** - * Feature that determines whether values written as empty Strings (from java.lang.String - * valued POJO properties) should be forced to be quoted. - */ - ALWAYS_QUOTE_EMPTY_STRINGS(false), - - /** - * Feature that determines whether values written as Nymbers (from {@code java.lang.Number} - * valued POJO properties) should be forced to be quoted, regardless of whether they - * actually need this. - * - * @since 2.16 - */ - ALWAYS_QUOTE_NUMBERS(false), - - /** - * Feature that determines whether quote characters within quoted String values are escaped - * using configured escape character, instead of being "doubled up" (that is: a quote character - * is written twice in a row). - *

- * Default value is false so that quotes are doubled as necessary, not escaped. - */ - ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR(false), - - /** - * Feature that determines whether control characters (non-printable) are escaped using the - * configured escape character. This feature allows LF and CR characters to be output as

\n
- * and
\r
instead of being echoed out. This is a compatibility feature for some - * parsers that can not read such output back in. - *

- * Default value is false so that control characters are echoed out (backwards compatible). - */ - ESCAPE_CONTROL_CHARS_WITH_ESCAPE_CHAR(false), - - /** - * Feature that determines whether a line-feed will be written at the end of content, - * after the last row of output. - *

- * NOTE! When disabling this feature it is important that - * {@link #flush()} is NOT called before {@link #close()} is called; - * the current implementation relies on ability to essentially remove the - * last linefeed that was appended in the output buffer. - *

- * Default value is {@code true} so all rows, including the last, are terminated by - * a line feed. - * - * @since 2.17 - */ - WRITE_LINEFEED_AFTER_LAST_ROW(true) - ; - - protected final boolean _defaultState; - protected final int _mask; - - /** - * Method that calculates bit set (flags) of all features that - * are enabled by default. - */ - public static int collectDefaults() - { - int flags = 0; - for (Feature f : values()) { - if (f.enabledByDefault()) { - flags |= f.getMask(); - } - } - return flags; - } - - private Feature(boolean defaultState) { - _defaultState = defaultState; - _mask = (1 << ordinal()); - } - - @Override - public boolean enabledIn(int flags) { return (flags & _mask) != 0; } - @Override - public boolean enabledByDefault() { return _defaultState; } - @Override - public int getMask() { return _mask; } - } - protected final static long MIN_INT_AS_LONG = Integer.MIN_VALUE; protected final static long MAX_INT_AS_LONG = Integer.MAX_VALUE; @@ -164,7 +30,7 @@ private Feature(boolean defaultState) { /** * Bit flag composed of bits that indicate which - * {@link CsvGenerator.Feature}s + * {@link CsvWriteFeature}s * are enabled. */ protected int _formatFeatures; @@ -431,7 +297,7 @@ private final void _writeFieldName(String name) throws JacksonException /********************************************************************** */ - public final boolean isEnabled(Feature f) { + public final boolean isEnabled(CsvWriteFeature f) { return (_formatFeatures & f.getMask()) != 0; } diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvMapper.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvMapper.java index d2e119229..3d885f6f8 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/CsvMapper.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvMapper.java @@ -55,21 +55,21 @@ protected MapperBuilderState _saveState() { /****************************************************************** */ - public Builder enable(CsvParser.Feature... features) { - for (CsvParser.Feature f : features) { + public Builder enable(CsvReadFeature... features) { + for (CsvReadFeature f : features) { _formatReadFeatures |= f.getMask(); } return this; } - public Builder disable(CsvParser.Feature... features) { - for (CsvParser.Feature f : features) { + public Builder disable(CsvReadFeature... features) { + for (CsvReadFeature f : features) { _formatReadFeatures &= ~f.getMask(); } return this; } - public Builder configure(CsvParser.Feature feature, boolean state) + public Builder configure(CsvReadFeature feature, boolean state) { if (state) { _formatReadFeatures |= feature.getMask(); @@ -79,21 +79,21 @@ public Builder configure(CsvParser.Feature feature, boolean state) return this; } - public Builder enable(CsvGenerator.Feature... features) { - for (CsvGenerator.Feature f : features) { + public Builder enable(CsvWriteFeature... features) { + for (CsvWriteFeature f : features) { _formatWriteFeatures |= f.getMask(); } return this; } - public Builder disable(CsvGenerator.Feature... features) { - for (CsvGenerator.Feature f : features) { + public Builder disable(CsvWriteFeature... features) { + for (CsvWriteFeature f : features) { _formatWriteFeatures &= ~f.getMask(); } return this; } - public Builder configure(CsvGenerator.Feature feature, boolean state) + public Builder configure(CsvWriteFeature feature, boolean state) { if (state) { _formatWriteFeatures |= feature.getMask(); diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvParser.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvParser.java index 82d151c1d..d5347db3e 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/CsvParser.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvParser.java @@ -34,170 +34,6 @@ public class CsvParser // Just to protect against bugs, DoS, limit number of column defs we may read private final static int MAX_COLUMNS = 99999; - /** - * Enumeration that defines all togglable features for CSV parsers - */ - public enum Feature - implements FormatFeature - { - /** - * Feature determines whether spaces around separator characters - * (commas) are to be automatically trimmed before being reported - * or not. - * Note that this does NOT force trimming of possible white space from - * within double-quoted values, but only those surrounding unquoted - * values (white space outside of double-quotes is never included regardless - * of trimming). - *

- * Default value is false, as per RFC-4180. - */ - TRIM_SPACES(false), - - /** - * Feature that determines how stream of records (usually CSV lines, but sometimes - * multiple lines when linefeeds are included in quoted values) is exposed: - * either as a sequence of Objects (false), or as an Array of Objects (true). - * Using stream of Objects is convenient when using - * ObjectMapper.readValues(...) - * and array of Objects convenient when binding to Lists or - * arrays of values. - *

- * Default value is false, meaning that by default a CSV document is exposed as - * a sequence of root-level Object entries. - */ - WRAP_AS_ARRAY(false), - - /** - * Feature that allows ignoring of unmappable "extra" columns; that is, values for - * columns that appear after columns for which types are defined. When disabled, - * an exception is thrown for such column values, but if enabled, they are - * silently ignored. - *

- * Feature is disabled by default. - */ - IGNORE_TRAILING_UNMAPPABLE(false), - - /** - * Feature that allows skipping input lines that are completely empty or blank (composed only of whitespace), - * instead of being decoded as lines of just a single column with an empty/blank String value (or, - * depending on binding, `null`). - *

- * Feature is disabled by default. - * - * @since 2.10 - */ - SKIP_EMPTY_LINES(false), - - /** - * Feature that allows there to be a trailing single extraneous data - * column that is empty. When this feature is disabled, any extraneous - * column, regardless of content will cause an exception to be thrown. - * Disabling this feature is only useful when - * IGNORE_TRAILING_UNMAPPABLE is also disabled. - */ - ALLOW_TRAILING_COMMA(true), - - /** - * Feature that allows accepting "hash comments" by default, similar to - * {@link CsvSchema#withAllowComments(boolean)}. If enabled, such comments - * are by default allowed on all columns of all documents. - */ - ALLOW_COMMENTS(false), - - /** - * Feature that allows failing (with a {@link CsvReadException}) in cases - * where number of column values encountered is less than number of columns - * declared in the active schema ("missing columns"). - *

- * Note that this feature has precedence over {@link #INSERT_NULLS_FOR_MISSING_COLUMNS} - *

- * Feature is disabled by default. - */ - FAIL_ON_MISSING_COLUMNS(false), - - /** - * Feature that allows failing (with a {@link CsvReadException}) in cases - * where number of header columns encountered is less than number of columns - * declared in the active schema (if there is one). - *

- * Feature is enabled by default - * - * @since 2.14 - */ - FAIL_ON_MISSING_HEADER_COLUMNS(true), - - /** - * Feature that allows "inserting" virtual key / `null` value pairs in case - * a row contains fewer columns than declared by configured schema. - * This typically has the effect of forcing an explicit `null` assigment (or - * corresponding "null value", if so configured) at databinding level. - * If disabled, no extra work is done and values for "missing" columns are - * not exposed as part of the token stream. - *

- * Note that this feature is only considered if - * {@link #FAIL_ON_MISSING_COLUMNS} - * is disabled. - *

- * Feature is disabled by default. - */ - INSERT_NULLS_FOR_MISSING_COLUMNS(false), - - /** - * Feature that enables coercing an empty {@link String} to `null`. - *

- * Note that if this setting is enabled, {@link #EMPTY_UNQUOTED_STRING_AS_NULL} - * has no effect. - * - * Feature is disabled by default for backwards compatibility. - */ - EMPTY_STRING_AS_NULL(false), - - /** - * Feature that enables coercing an empty un-quoted {@link String} to `null`. - * This feature allow differentiating between an empty quoted {@link String} and an empty un-quoted {@link String}. - *

- * Note that this feature is only considered if - * {@link #EMPTY_STRING_AS_NULL} - * is disabled. - *

- * Feature is disabled by default for backwards compatibility. - * - * @since 2.18 - */ - EMPTY_UNQUOTED_STRING_AS_NULL(false), - ; - - final boolean _defaultState; - final int _mask; - - /** - * Method that calculates bit set (flags) of all features that - * are enabled by default. - */ - public static int collectDefaults() - { - int flags = 0; - for (Feature f : values()) { - if (f.enabledByDefault()) { - flags |= f.getMask(); - } - } - return flags; - } - - private Feature(boolean defaultState) { - _defaultState = defaultState; - _mask = (1 << ordinal()); - } - - @Override - public boolean enabledByDefault() { return _defaultState; } - @Override - public boolean enabledIn(int flags) { return (flags & _mask) != 0; } - @Override - public int getMask() { return _mask; } - } - private final static CsvSchema EMPTY_SCHEMA; static { EMPTY_SCHEMA = CsvSchema.emptySchema(); @@ -271,14 +107,14 @@ private Feature(boolean defaultState) { /** * State in which we should expose name token for a "missing column" * (for which placeholder `null` value is to be added as well); - * see {@link Feature#INSERT_NULLS_FOR_MISSING_COLUMNS} for details. + * see {@link CsvReadFeature#INSERT_NULLS_FOR_MISSING_COLUMNS} for details. */ protected final static int STATE_MISSING_NAME = 7; /** * State in which we should expose `null` value token as a value for * "missing" column; - * see {@link Feature#INSERT_NULLS_FOR_MISSING_COLUMNS} for details. + * see {@link CsvReadFeature#INSERT_NULLS_FOR_MISSING_COLUMNS} for details. */ protected final static int STATE_MISSING_VALUE = 8; @@ -414,8 +250,8 @@ public CsvParser(ObjectReadContext readCtxt, IOContext ioCtxt, _reader = new CsvDecoder(ioCtxt, this, reader, schema, _textBuffer, stdFeatures, csvFeatures); _setSchema(schema); - _cfgEmptyStringAsNull = CsvParser.Feature.EMPTY_STRING_AS_NULL.enabledIn(csvFeatures); - _cfgEmptyUnquotedStringAsNull = Feature.EMPTY_UNQUOTED_STRING_AS_NULL.enabledIn(csvFeatures); + _cfgEmptyStringAsNull = CsvReadFeature.EMPTY_STRING_AS_NULL.enabledIn(csvFeatures); + _cfgEmptyUnquotedStringAsNull = CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL.enabledIn(csvFeatures); } /* @@ -481,33 +317,33 @@ protected void _releaseBuffers() { } /** * Method for enabling specified CSV feature - * (check {@link Feature} for list of features) + * (check {@link CsvReadFeature} for list of features) */ - public JsonParser enable(CsvParser.Feature f) + public JsonParser enable(CsvReadFeature f) { _formatFeatures |= f.getMask(); - _cfgEmptyStringAsNull = CsvParser.Feature.EMPTY_STRING_AS_NULL.enabledIn(_formatFeatures); - _cfgEmptyUnquotedStringAsNull = Feature.EMPTY_UNQUOTED_STRING_AS_NULL.enabledIn(_formatFeatures); + _cfgEmptyStringAsNull = CsvReadFeature.EMPTY_STRING_AS_NULL.enabledIn(_formatFeatures); + _cfgEmptyUnquotedStringAsNull = CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL.enabledIn(_formatFeatures); return this; } /** * Method for disabling specified CSV feature - * (check {@link Feature} for list of features) + * (check {@link CsvReadFeature} for list of features) */ - public JsonParser disable(CsvParser.Feature f) + public JsonParser disable(CsvReadFeature f) { _formatFeatures &= ~f.getMask(); - _cfgEmptyStringAsNull = CsvParser.Feature.EMPTY_STRING_AS_NULL.enabledIn(_formatFeatures); - _cfgEmptyUnquotedStringAsNull = Feature.EMPTY_UNQUOTED_STRING_AS_NULL.enabledIn(_formatFeatures); + _cfgEmptyStringAsNull = CsvReadFeature.EMPTY_STRING_AS_NULL.enabledIn(_formatFeatures); + _cfgEmptyUnquotedStringAsNull = CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL.enabledIn(_formatFeatures); return this; } /** * Method for enabling or disabling specified CSV feature - * (check {@link Feature} for list of features) + * (check {@link CsvReadFeature} for list of features) */ - public JsonParser configure(CsvParser.Feature f, boolean state) + public JsonParser configure(CsvReadFeature f, boolean state) { if (state) { enable(f); @@ -518,10 +354,10 @@ public JsonParser configure(CsvParser.Feature f, boolean state) } /** - * Method for checking whether specified CSV {@link Feature} + * Method for checking whether specified CSV {@link CsvReadFeature} * is enabled. */ - public boolean isEnabled(CsvParser.Feature f) { + public boolean isEnabled(CsvReadFeature f) { return (_formatFeatures & f.getMask()) != 0; } @@ -802,7 +638,7 @@ protected void _readHeaderLine() throws JacksonException { } // [dataformats-text#204]: Drop trailing empty name if so instructed - if (CsvParser.Feature.ALLOW_TRAILING_COMMA.enabledIn(_formatFeatures)) { + if (CsvReadFeature.ALLOW_TRAILING_COMMA.enabledIn(_formatFeatures)) { builder.dropLastColumnIfEmpty(); } @@ -817,7 +653,7 @@ protected void _readHeaderLine() throws JacksonException { } // [dataformats-text#285]: Are we missing something? int diff = schemaColumnCount - newColumnCount; - if ((diff > 0) && Feature.FAIL_ON_MISSING_HEADER_COLUMNS.enabledIn(_formatFeatures)) { + if ((diff > 0) && CsvReadFeature.FAIL_ON_MISSING_HEADER_COLUMNS.enabledIn(_formatFeatures)) { Set oldColumnNames = new LinkedHashSet<>(); _schema.getColumnNames(oldColumnNames); oldColumnNames.removeAll(newSchema.getColumnNames()); @@ -852,7 +688,7 @@ protected JsonToken _handleStartDoc() throws JacksonException // Only one real complication, actually; empty documents (zero bytes). // Those have no entries. Should be easy enough to detect like so: - final boolean wrapAsArray = Feature.WRAP_AS_ARRAY.enabledIn(_formatFeatures); + final boolean wrapAsArray = CsvReadFeature.WRAP_AS_ARRAY.enabledIn(_formatFeatures); if (!_reader.hasMoreInput()) { _state = STATE_DOC_END; // but even empty sequence must still be wrapped in logical array @@ -995,7 +831,7 @@ protected JsonToken _handleArrayValue() throws JacksonException _currentValue = _arrayValue.substring(offset, end); _arrayValueStart = end+_arraySeparator.length(); } - if (isEnabled(Feature.TRIM_SPACES)) { + if (isEnabled(CsvReadFeature.TRIM_SPACES)) { _currentValue = _currentValue.trim(); } if (_isNullValue(_currentValue)) { @@ -1027,7 +863,7 @@ protected JsonToken _handleExtraColumn(String value) throws JacksonException } _currentName = null; // With [dataformat-csv#95] we'll simply ignore extra - if (Feature.IGNORE_TRAILING_UNMAPPABLE.enabledIn(_formatFeatures)) { + if (CsvReadFeature.IGNORE_TRAILING_UNMAPPABLE.enabledIn(_formatFeatures)) { _state = STATE_SKIP_EXTRA_COLUMNS; return _skipUntilEndOfLine(); } @@ -1035,7 +871,7 @@ protected JsonToken _handleExtraColumn(String value) throws JacksonException // 14-Mar-2012, tatu: As per [dataformat-csv#1], let's allow one specific case // of extra: if we get just one all-whitespace entry, that can be just skipped _state = STATE_SKIP_EXTRA_COLUMNS; - if (_columnIndex == _columnCount && Feature.ALLOW_TRAILING_COMMA.enabledIn(_formatFeatures)) { + if (_columnIndex == _columnCount && CsvReadFeature.ALLOW_TRAILING_COMMA.enabledIn(_formatFeatures)) { value = value.trim(); if (value.isEmpty()) { // if so, need to verify we then get the end-of-record; @@ -1063,14 +899,14 @@ protected JsonToken _handleExtraColumn(String value) throws JacksonException */ protected JsonToken _handleMissingColumns() throws JacksonException { - if (Feature.FAIL_ON_MISSING_COLUMNS.enabledIn(_formatFeatures)) { + if (CsvReadFeature.FAIL_ON_MISSING_COLUMNS.enabledIn(_formatFeatures)) { // First: to allow recovery, set states to expose next line, if any _handleObjectRowEnd(); // and then report actual problem return _reportCsvReadError("Not enough column values: expected %d, found %d", _columnCount, _columnIndex); } - if (Feature.INSERT_NULLS_FOR_MISSING_COLUMNS.enabledIn(_formatFeatures)) { + if (CsvReadFeature.INSERT_NULLS_FOR_MISSING_COLUMNS.enabledIn(_formatFeatures)) { _state = STATE_MISSING_VALUE; _currentName = _schema.columnName(_columnIndex); _currentValue = null; diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvReadFeature.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvReadFeature.java new file mode 100644 index 000000000..21f1c07ab --- /dev/null +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvReadFeature.java @@ -0,0 +1,163 @@ +package tools.jackson.dataformat.csv; + +import tools.jackson.core.FormatFeature; + +/** + * Enumeration that defines all togglable features for CSV parsers + *

+ * NOTE: in Jackson 2.x this was named {@code CsvParser.Feature}. + */ +public enum CsvReadFeature + implements FormatFeature +{ + /** + * Feature determines whether spaces around separator characters + * (commas) are to be automatically trimmed before being reported + * or not. + * Note that this does NOT force trimming of possible white space from + * within double-quoted values, but only those surrounding unquoted + * values (white space outside of double-quotes is never included regardless + * of trimming). + *

+ * Default value is false, as per RFC-4180. + */ + TRIM_SPACES(false), + + /** + * Feature that determines how stream of records (usually CSV lines, but sometimes + * multiple lines when linefeeds are included in quoted values) is exposed: + * either as a sequence of Objects (false), or as an Array of Objects (true). + * Using stream of Objects is convenient when using + * ObjectMapper.readValues(...) + * and array of Objects convenient when binding to Lists or + * arrays of values. + *

+ * Default value is false, meaning that by default a CSV document is exposed as + * a sequence of root-level Object entries. + */ + WRAP_AS_ARRAY(false), + + /** + * Feature that allows ignoring of unmappable "extra" columns; that is, values for + * columns that appear after columns for which types are defined. When disabled, + * an exception is thrown for such column values, but if enabled, they are + * silently ignored. + *

+ * Feature is disabled by default. + */ + IGNORE_TRAILING_UNMAPPABLE(false), + + /** + * Feature that allows skipping input lines that are completely empty or blank (composed only of whitespace), + * instead of being decoded as lines of just a single column with an empty/blank String value (or, + * depending on binding, `null`). + *

+ * Feature is disabled by default. + */ + SKIP_EMPTY_LINES(false), + + /** + * Feature that allows there to be a trailing single extraneous data + * column that is empty. When this feature is disabled, any extraneous + * column, regardless of content will cause an exception to be thrown. + * Disabling this feature is only useful when + * IGNORE_TRAILING_UNMAPPABLE is also disabled. + */ + ALLOW_TRAILING_COMMA(true), + + /** + * Feature that allows accepting "hash comments" by default, similar to + * {@link CsvSchema#withAllowComments(boolean)}. If enabled, such comments + * are by default allowed on all columns of all documents. + */ + ALLOW_COMMENTS(false), + + /** + * Feature that allows failing (with a {@link CsvReadException}) in cases + * where number of column values encountered is less than number of columns + * declared in the active schema ("missing columns"). + *

+ * Note that this feature has precedence over {@link #INSERT_NULLS_FOR_MISSING_COLUMNS} + *

+ * Feature is disabled by default. + */ + FAIL_ON_MISSING_COLUMNS(false), + + /** + * Feature that allows failing (with a {@link CsvReadException}) in cases + * where number of header columns encountered is less than number of columns + * declared in the active schema (if there is one). + *

+ * Feature is enabled by default. + */ + FAIL_ON_MISSING_HEADER_COLUMNS(true), + + /** + * Feature that allows "inserting" virtual key / `null` value pairs in case + * a row contains fewer columns than declared by configured schema. + * This typically has the effect of forcing an explicit `null` assigment (or + * corresponding "null value", if so configured) at databinding level. + * If disabled, no extra work is done and values for "missing" columns are + * not exposed as part of the token stream. + *

+ * Note that this feature is only considered if + * {@link #FAIL_ON_MISSING_COLUMNS} + * is disabled. + *

+ * Feature is disabled by default. + */ + INSERT_NULLS_FOR_MISSING_COLUMNS(false), + + /** + * Feature that enables coercing an empty {@link String} to `null`. + *

+ * Note that if this setting is enabled, {@link #EMPTY_UNQUOTED_STRING_AS_NULL} + * has no effect. + * + * Feature is disabled by default for backwards compatibility. + */ + EMPTY_STRING_AS_NULL(false), + + /** + * Feature that enables coercing an empty un-quoted {@link String} to `null`. + * This feature allow differentiating between an empty quoted {@link String} and an empty un-quoted {@link String}. + *

+ * Note that this feature is only considered if + * {@link #EMPTY_STRING_AS_NULL} + * is disabled. + *

+ * Feature is disabled by default for backwards compatibility. + */ + EMPTY_UNQUOTED_STRING_AS_NULL(false), + ; + + private final boolean _defaultState; + private final int _mask; + + /** + * Method that calculates bit set (flags) of all features that + * are enabled by default. + */ + public static int collectDefaults() + { + int flags = 0; + for (CsvReadFeature f : values()) { + if (f.enabledByDefault()) { + flags |= f.getMask(); + } + } + return flags; + } + + private CsvReadFeature(boolean defaultState) { + _defaultState = defaultState; + _mask = (1 << ordinal()); + } + + @Override + public boolean enabledByDefault() { return _defaultState; } + @Override + public boolean enabledIn(int flags) { return (flags & _mask) != 0; } + @Override + public int getMask() { return _mask; } +} diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/CsvWriteFeature.java b/csv/src/main/java/tools/jackson/dataformat/csv/CsvWriteFeature.java new file mode 100644 index 000000000..4d7b19cd2 --- /dev/null +++ b/csv/src/main/java/tools/jackson/dataformat/csv/CsvWriteFeature.java @@ -0,0 +1,129 @@ +package tools.jackson.dataformat.csv; + +import tools.jackson.core.FormatFeature; + +/** + * Enumeration that defines all togglable features for CSV writers + *

+ * NOTE: in Jackson 2.x this was named {@code CsvGenerator.Feature}. + */ +public enum CsvWriteFeature + implements FormatFeature +{ + /** + * Feature that determines how much work is done before determining that + * a column value requires quoting: when set as true, full + * check is made to only use quoting when it is strictly necessary; + * but when false, a faster but more conservative check + * is made, and possibly quoting is used for values that might not need it. + * Trade-offs is basically between optimal/minimal quoting (true), and + * faster handling (false). + * Faster check involves only checking first N characters of value, as well + * as possible looser checks. + *

+ * Note, however, that regardless setting, all values that need to be quoted + * will be: it is just that when set to false, other values may + * also be quoted (to avoid having to do more expensive checks). + *

+ * Default value is false for "loose" (approximate, conservative) + * checking. + */ + STRICT_CHECK_FOR_QUOTING(false), + + /** + * Feature that determines whether columns without matching value may be omitted, + * when they are the last values of the row. + * If true, values and separators between values may be omitted, to slightly reduce + * length of the row; if false, separators need to stay in place and values + * are indicated by empty Strings. + */ + OMIT_MISSING_TAIL_COLUMNS(false), + + /** + * Feature that determines whether values written as Strings (from java.lang.String + * valued POJO properties) should be forced to be quoted, regardless of whether they + * actually need this. + * Note that this feature has precedence over {@link #STRICT_CHECK_FOR_QUOTING}, when + * both would be applicable. + * Note that this setting does NOT affect quoting of typed values like {@code Number}s + * or {@code Boolean}s. + */ + ALWAYS_QUOTE_STRINGS(false), + + /** + * Feature that determines whether values written as empty Strings (from java.lang.String + * valued POJO properties) should be forced to be quoted. + */ + ALWAYS_QUOTE_EMPTY_STRINGS(false), + + /** + * Feature that determines whether values written as Nymbers (from {@code java.lang.Number} + * valued POJO properties) should be forced to be quoted, regardless of whether they + * actually need this. + */ + ALWAYS_QUOTE_NUMBERS(false), + + /** + * Feature that determines whether quote characters within quoted String values are escaped + * using configured escape character, instead of being "doubled up" (that is: a quote character + * is written twice in a row). + *

+ * Default value is false so that quotes are doubled as necessary, not escaped. + */ + ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR(false), + + /** + * Feature that determines whether control characters (non-printable) are escaped using the + * configured escape character. This feature allows LF and CR characters to be output as

\n
+ * and
\r
instead of being echoed out. This is a compatibility feature for some + * parsers that can not read such output back in. + *

+ * Default value is false so that control characters are echoed out (backwards compatible). + */ + ESCAPE_CONTROL_CHARS_WITH_ESCAPE_CHAR(false), + + /** + * Feature that determines whether a line-feed will be written at the end of content, + * after the last row of output. + *

+ * NOTE! When disabling this feature it is important that + * {@link CsvGenerator#flush()} is NOT called before {@link CsvGenerator#close()} is called; + * the current implementation relies on ability to essentially remove the + * last linefeed that was appended in the output buffer. + *

+ * Default value is {@code true} so all rows, including the last, are terminated by + * a line feed. + */ + WRITE_LINEFEED_AFTER_LAST_ROW(true) + ; + + private final boolean _defaultState; + private final int _mask; + + /** + * Method that calculates bit set (flags) of all features that + * are enabled by default. + */ + public static int collectDefaults() + { + int flags = 0; + for (CsvWriteFeature f : values()) { + if (f.enabledByDefault()) { + flags |= f.getMask(); + } + } + return flags; + } + + private CsvWriteFeature(boolean defaultState) { + _defaultState = defaultState; + _mask = (1 << ordinal()); + } + + @Override + public boolean enabledIn(int flags) { return (flags & _mask) != 0; } + @Override + public boolean enabledByDefault() { return _defaultState; } + @Override + public int getMask() { return _mask; } +} diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvDecoder.java b/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvDecoder.java index 59056061c..e6a98118d 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvDecoder.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvDecoder.java @@ -15,6 +15,7 @@ import tools.jackson.core.util.SimpleStreamReadContext; import tools.jackson.core.util.TextBuffer; import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.CsvSchema; /** @@ -295,10 +296,10 @@ public CsvDecoder(IOContext ctxt, CsvParser owner, Reader r, _inputReader = r; _textBuffer = textBuffer; _autoCloseInput = StreamReadFeature.AUTO_CLOSE_SOURCE.enabledIn(stdFeatures); - _allowComments = CsvParser.Feature.ALLOW_COMMENTS.enabledIn(csvFeatures); - _trimSpaces = CsvParser.Feature.TRIM_SPACES.enabledIn(csvFeatures); - _skipBlankLines = CsvParser.Feature.SKIP_EMPTY_LINES.enabledIn(csvFeatures); - _trimSpaces = CsvParser.Feature.TRIM_SPACES.enabledIn(csvFeatures); + _allowComments = CsvReadFeature.ALLOW_COMMENTS.enabledIn(csvFeatures); + _trimSpaces = CsvReadFeature.TRIM_SPACES.enabledIn(csvFeatures); + _skipBlankLines = CsvReadFeature.SKIP_EMPTY_LINES.enabledIn(csvFeatures); + _trimSpaces = CsvReadFeature.TRIM_SPACES.enabledIn(csvFeatures); _inputBuffer = ctxt.allocTokenBuffer(); _bufferRecyclable = true; // since we allocated it _tokenInputRow = -1; diff --git a/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvEncoder.java b/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvEncoder.java index aca7e2278..deecc701a 100644 --- a/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvEncoder.java +++ b/csv/src/main/java/tools/jackson/dataformat/csv/impl/CsvEncoder.java @@ -12,10 +12,9 @@ import tools.jackson.core.io.CharacterEscapes; import tools.jackson.core.io.IOContext; import tools.jackson.core.io.NumberOutput; - -import tools.jackson.dataformat.csv.CsvGenerator; import tools.jackson.dataformat.csv.CsvSchema; import tools.jackson.dataformat.csv.CsvWriteException; +import tools.jackson.dataformat.csv.CsvWriteFeature; /** * Helper class that handles actual low-level construction of @@ -193,13 +192,13 @@ public CsvEncoder(IOContext ctxt, int csvFeatures, Writer out, CsvSchema schema, _ioContext = ctxt; _csvFeatures = csvFeatures; _cfgUseFastDoubleWriter = useFastDoubleWriter; - _cfgOptimalQuoting = CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING.enabledIn(csvFeatures); - _cfgIncludeMissingTail = !CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS.enabledIn(_csvFeatures); - _cfgAlwaysQuoteStrings = CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS.enabledIn(csvFeatures); - _cfgAlwaysQuoteEmptyStrings = CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS.enabledIn(csvFeatures); - _cfgAlwaysQuoteNumbers = CsvGenerator.Feature.ALWAYS_QUOTE_NUMBERS.enabledIn(csvFeatures); - _cfgEscapeQuoteCharWithEscapeChar = CsvGenerator.Feature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR.enabledIn(csvFeatures); - _cfgEscapeControlCharWithEscapeChar = CsvGenerator.Feature.ESCAPE_CONTROL_CHARS_WITH_ESCAPE_CHAR.enabledIn(csvFeatures); + _cfgOptimalQuoting = CsvWriteFeature.STRICT_CHECK_FOR_QUOTING.enabledIn(csvFeatures); + _cfgIncludeMissingTail = !CsvWriteFeature.OMIT_MISSING_TAIL_COLUMNS.enabledIn(_csvFeatures); + _cfgAlwaysQuoteStrings = CsvWriteFeature.ALWAYS_QUOTE_STRINGS.enabledIn(csvFeatures); + _cfgAlwaysQuoteEmptyStrings = CsvWriteFeature.ALWAYS_QUOTE_EMPTY_STRINGS.enabledIn(csvFeatures); + _cfgAlwaysQuoteNumbers = CsvWriteFeature.ALWAYS_QUOTE_NUMBERS.enabledIn(csvFeatures); + _cfgEscapeQuoteCharWithEscapeChar = CsvWriteFeature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR.enabledIn(csvFeatures); + _cfgEscapeControlCharWithEscapeChar = CsvWriteFeature.ESCAPE_CONTROL_CHARS_WITH_ESCAPE_CHAR.enabledIn(csvFeatures); _outputBuffer = ctxt.allocConcatBuffer(); _bufferRecyclable = true; @@ -1097,7 +1096,7 @@ public void close(boolean autoClose, boolean flushStream) throws IOException { // May need to remove the linefeed appended after the last row written // (if not yet done) - if (!CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW.enabledIn(_csvFeatures)) { + if (!CsvWriteFeature.WRITE_LINEFEED_AFTER_LAST_ROW.enabledIn(_csvFeatures)) { _removeTrailingLF(); } _flushBuffer(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/BlogPost2021AprilTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/BlogPost2021AprilTest.java index 79bc62fdd..dc727921f 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/BlogPost2021AprilTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/BlogPost2021AprilTest.java @@ -8,7 +8,7 @@ import tools.jackson.core.type.TypeReference; import tools.jackson.databind.MappingIterator; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.CsvSchema; import tools.jackson.dataformat.csv.ModuleTestBase; @@ -36,7 +36,7 @@ public void testAsListOfLists() throws Exception { List> all = MAPPER .readerFor(new TypeReference>>() {} ) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValue(SIMPLE_CSV); _assertListOfLists(all); } @@ -45,7 +45,7 @@ public void testAsSequenceOfListsOfStrings() throws Exception { MappingIterator> it = MAPPER .readerForListOf(String.class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(SIMPLE_CSV); List> all = it.readAll(); /* while (it.hasNextValue()) { diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/CSVBigStringsTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/CSVBigStringsTest.java index def6dab75..5c7569930 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/CSVBigStringsTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/CSVBigStringsTest.java @@ -9,7 +9,7 @@ import tools.jackson.dataformat.csv.CsvFactory; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.ModuleTestBase; public class CSVBigStringsTest extends ModuleTestBase @@ -31,7 +31,7 @@ public void testBigString() throws Exception try { MappingIterator> it = MAPPER .readerForListOf(String.class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(generateCsv(TOO_LONG_STRING_VALUE_LEN)); it.readAll(); fail("expected StreamConstraintsException"); @@ -47,7 +47,7 @@ public void testBiggerString() throws Exception try { MappingIterator> it = MAPPER .readerForListOf(String.class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(generateCsv(TOO_LONG_STRING_VALUE_LEN)); it.readAll(); fail("expected StreamConstraintsException"); @@ -65,7 +65,7 @@ public void testUnlimitedString() throws Exception final int len = TOO_LONG_STRING_VALUE_LEN; MappingIterator> it = newCsvMapperWithUnlimitedStringSizeSupport() .readerForListOf(String.class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(generateCsv(len)); List> results = it.readAll(); assertEquals(1, results.size()); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/CommentsTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/CommentsTest.java index b2543302f..da2d6cbc3 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/CommentsTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/CommentsTest.java @@ -2,7 +2,7 @@ import tools.jackson.databind.MappingIterator; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.ModuleTestBase; import java.util.Map; @@ -21,9 +21,9 @@ public void testWithoutComments() throws Exception String[] row; MappingIterator it = mapper.readerFor(String[].class) // to handle comments that follow leading spaces - .with(CsvParser.Feature.TRIM_SPACES) + .with(CsvReadFeature.TRIM_SPACES) // should not be needed but seems to be... - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .with(mapper.schema().withoutComments()).readValues(CSV_WITH_COMMENTS); row = it.nextValue(); @@ -57,9 +57,9 @@ public void testSimpleComments() throws Exception CsvMapper mapper = mapperForCsv(); MappingIterator it = mapper.readerFor(String[].class) .with(mapper.schema().withComments()) - .with(CsvParser.Feature.TRIM_SPACES) + .with(CsvReadFeature.TRIM_SPACES) // should not be needed but seems to be... - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(CSV_WITH_COMMENTS); // first row the same @@ -86,7 +86,7 @@ public void testLeadingComments() throws Exception MappingIterator it = mapper.readerFor(String[].class) .with(mapper.schema().withComments()) // should not be needed but seems to be... - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues("# first\n#second\n1,2\n"); // first row the same @@ -122,13 +122,13 @@ public void testCommentsWithHeaderRow() throws Exception public void testSimpleCommentsWithDefaultProp() throws Exception { CsvMapper mapper = mapperBuilder() - .enable(CsvParser.Feature.ALLOW_COMMENTS) - .enable(CsvParser.Feature.WRAP_AS_ARRAY) + .enable(CsvReadFeature.ALLOW_COMMENTS) + .enable(CsvReadFeature.WRAP_AS_ARRAY) .build(); final String CSV = "# comment!\na,b\n"; MappingIterator it = mapper.readerFor(String[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(CSV); String[] row = it.nextValue(); // assertEquals(2, row.length); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyStringAsNullTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyStringAsNullTest.java index 7ba78226a..24d9e5493 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyStringAsNullTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyStringAsNullTest.java @@ -4,7 +4,7 @@ import tools.jackson.databind.MappingIterator; import tools.jackson.databind.ObjectReader; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.ModuleTestBase; /** @@ -55,7 +55,7 @@ public void testEmptyStringAsNullEnabled() throws Exception { ObjectReader objectReader = MAPPER .readerFor(TestUser.class) .with(MAPPER.schemaFor(TestUser.class)) - .with(CsvParser.Feature.EMPTY_STRING_AS_NULL); + .with(CsvReadFeature.EMPTY_STRING_AS_NULL); String csv = "Grace,,Hopper"; // execute @@ -74,8 +74,8 @@ public void testEmptyStringAsNullNonPojo() throws Exception String csv = "Grace,,Hopper"; ObjectReader r = MAPPER.reader() - .with(CsvParser.Feature.EMPTY_STRING_AS_NULL) - .with(CsvParser.Feature.WRAP_AS_ARRAY); + .with(CsvReadFeature.EMPTY_STRING_AS_NULL) + .with(CsvReadFeature.WRAP_AS_ARRAY); try (MappingIterator it1 = r.forType(Object[].class).readValues(csv)) { Object[] array1 = it1.next(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyUnquotedStringAsNullTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyUnquotedStringAsNullTest.java index eb2a498ad..80ebc1bb7 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyUnquotedStringAsNullTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/EmptyUnquotedStringAsNullTest.java @@ -56,7 +56,7 @@ public void testSimpleParseEmptyUnquotedStringAsNull() throws IOException { ObjectReader objectReader = MAPPER .readerFor(TestUser.class) .with(MAPPER.schemaFor(TestUser.class)) - .with(CsvParser.Feature.EMPTY_UNQUOTED_STRING_AS_NULL); + .with(CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL); String csv = "Grace,,Hopper"; // execute @@ -79,7 +79,7 @@ public void testSimpleParseEmptyQuotedStringAsNonNull() throws IOException { ObjectReader objectReader = MAPPER .readerFor(TestUser.class) .with(MAPPER.schemaFor(TestUser.class)) - .with(CsvParser.Feature.EMPTY_UNQUOTED_STRING_AS_NULL); + .with(CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL); String csv = "Grace,\"\",Hopper"; // execute @@ -98,8 +98,8 @@ public void testEmptyUnquotedStringAsNullNonPojo() throws Exception String csv = "Grace,,Hopper"; ObjectReader r = MAPPER.reader() - .with(CsvParser.Feature.EMPTY_UNQUOTED_STRING_AS_NULL) - .with(CsvParser.Feature.WRAP_AS_ARRAY); + .with(CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL) + .with(CsvReadFeature.WRAP_AS_ARRAY); try (MappingIterator it1 = r.forType(Object[].class).readValues(csv)) { Object[] array1 = it1.next(); @@ -122,8 +122,8 @@ public void testEmptyQuotedStringAsNonNullNonPojo() throws Exception String csv = "Grace,\"\",Hopper"; ObjectReader r = MAPPER.reader() - .with(CsvParser.Feature.EMPTY_UNQUOTED_STRING_AS_NULL) - .with(CsvParser.Feature.WRAP_AS_ARRAY); + .with(CsvReadFeature.EMPTY_UNQUOTED_STRING_AS_NULL) + .with(CsvReadFeature.WRAP_AS_ARRAY); try (MappingIterator it1 = r.forType(Object[].class).readValues(csv)) { Object[] array1 = it1.next(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/IgnoreUnmappableTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/IgnoreUnmappableTest.java index dedb9cade..383b5199f 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/IgnoreUnmappableTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/IgnoreUnmappableTest.java @@ -25,7 +25,7 @@ public void testSimpleIgnoral() throws Exception // first: throw exception(s) with default settings MappingIterator it = MAPPER.readerFor(StringPair.class) .with(schema) - .without(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE) + .without(CsvReadFeature.IGNORE_TRAILING_UNMAPPABLE) .readValues(INPUT); try { @@ -52,7 +52,7 @@ public void testSimpleIgnoral() throws Exception // But with settings... it = MAPPER.readerFor(StringPair.class) .with(schema) - .with(CsvParser.Feature.IGNORE_TRAILING_UNMAPPABLE) + .with(CsvReadFeature.IGNORE_TRAILING_UNMAPPABLE) .readValues(INPUT); pair = it.nextValue(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumns285Test.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumns285Test.java index f8dc2d1dc..3d4b1fa8f 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumns285Test.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumns285Test.java @@ -51,7 +51,7 @@ public void testAllowMissingWithReorder() throws Exception MappingIterator> it = MAPPER .readerFor(Map.class) .with(csvSchema) - .without(CsvParser.Feature.FAIL_ON_MISSING_HEADER_COLUMNS) + .without(CsvReadFeature.FAIL_ON_MISSING_HEADER_COLUMNS) .readValues(CSV); assertTrue(it.hasNext()); Map result = it.nextValue(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumnsTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumnsTest.java index 14be8dea1..d48f2702a 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumnsTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/MissingColumnsTest.java @@ -65,7 +65,7 @@ public void testInjectMissingAsNulls() throws Exception { ObjectReader r = MAPPER.readerFor(ABC.class) .with(SCHEMA_ABC) - .with(CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS); + .with(CsvReadFeature.INSERT_NULLS_FOR_MISSING_COLUMNS); // check with various number of missing; but first with no missing ABC result = r.readValue("first,second,third\n"); @@ -95,7 +95,7 @@ public void testFailOnMissingColumns() throws Exception { ObjectReader r = MAPPER.readerFor(ABC.class) .with(SCHEMA_ABC) - .with(CsvParser.Feature.FAIL_ON_MISSING_COLUMNS); + .with(CsvReadFeature.FAIL_ON_MISSING_COLUMNS); // check with various number of missing, as well as recovery MappingIterator it = r.readValues( diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/NullReadTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/NullReadTest.java index 4b97bc26e..9214ebffa 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/NullReadTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/NullReadTest.java @@ -152,7 +152,7 @@ public void testEmptyStringAsNull330() throws Exception MappingIterator iterator = MAPPER .readerFor(Row330.class) - .with(CsvParser.Feature.EMPTY_STRING_AS_NULL) + .with(CsvReadFeature.EMPTY_STRING_AS_NULL) .with(headerSchema) .readValues(DOC); Row330 row = iterator.next(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserLocation483Test.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserLocation483Test.java index 2e8bf69d4..f404795dd 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserLocation483Test.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserLocation483Test.java @@ -5,7 +5,7 @@ import tools.jackson.core.JacksonException; import tools.jackson.databind.MappingIterator; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.ModuleTestBase; public class ParserLocation483Test extends ModuleTestBase @@ -17,7 +17,7 @@ public void testAsSequence() throws Exception { try (MappingIterator> reader = MAPPER .readerForListOf(String.class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues("name,dob\n\"string without end")) { reader.readAll(); } catch (JacksonException e) { diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserTrimSpacesTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserTrimSpacesTest.java index c5ab6343d..9fb5ed068 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserTrimSpacesTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/ParserTrimSpacesTest.java @@ -29,7 +29,7 @@ public void testNonTrimming() throws Exception { CsvMapper mapper = mapperForCsv(); MappingIterator it = mapper.readerWithSchemaFor(Entry.class) - .without(CsvParser.Feature.TRIM_SPACES) + .without(CsvReadFeature.TRIM_SPACES) .readValues( "a, b, c \n 1,2,\"3 \"\n" ); @@ -52,7 +52,7 @@ public void testNonTrimming() throws Exception // [dataformat-csv#81]: also need to be able to re-enable it = mapper.readerWithSchemaFor(Entry.class) - .with(CsvParser.Feature.TRIM_SPACES) + .with(CsvReadFeature.TRIM_SPACES) .readValues("a, b, c \n"); assertTrue(it.hasNext()); assertNotNull(entry = it.nextValue()); @@ -67,7 +67,7 @@ public void testTrimming() throws Exception { CsvMapper mapper = mapperForCsv(); MappingIterator it = mapper.readerWithSchemaFor(Entry.class) - .with(CsvParser.Feature.TRIM_SPACES) + .with(CsvReadFeature.TRIM_SPACES) .readValues( "a, b, c\t\n 1,2,\" 3\" \n\"ab\t\" ,\"c\", \n" ); @@ -101,7 +101,7 @@ public void testTrimmingTabSeparated() throws Exception CsvMapper mapper = mapperForCsv(); CsvSchema schema = mapper.schemaFor(Entry.class).withColumnSeparator('\t'); MappingIterator it = mapper.readerFor(Entry.class).with(schema) - .with(CsvParser.Feature.TRIM_SPACES) + .with(CsvReadFeature.TRIM_SPACES) .readValues( "a\t\t c\n 1\t2\t\" 3\" \n\"ab\" \t\"c \t\"\t \n" ); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/ReadSequencesTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/ReadSequencesTest.java index 70982fbef..49a70b95a 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/ReadSequencesTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/ReadSequencesTest.java @@ -47,7 +47,7 @@ public String toString() { public void testAsSequence() throws Exception { MappingIterator it = MAPPER.readerWithSchemaFor(Entry.class) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues( "1,2\n-3,0\n5,6\n"); Entry entry; @@ -72,7 +72,7 @@ public void testAsSequence() throws Exception public void testAsWrappedArray() throws Exception { Entry[] entries = MAPPER.readerWithSchemaFor(Entry.class).forType(Entry[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValue("1,2\n0,0\n123,123456789\n"); assertEquals(3, entries.length); assertEquals(1, entries[0].x); @@ -98,7 +98,7 @@ public void testLongerUnwrapped() throws Exception assertEquals(EXPECTED_BYTES, bytes.length); MappingIterator it = MAPPER.readerFor(Entry.class).with(schema) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues(bytes, 0, bytes.length); verifySame(it, entries); bytes = null; @@ -109,7 +109,7 @@ public void testLongerUnwrapped() throws Exception it.close(); it = MAPPER.readerFor(Entry.class).with(schema) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues(text); verifySame(it, entries); it.close(); @@ -121,7 +121,7 @@ public void testRawObjectArrays() throws Exception { final String CSV = "a,b\nc,d\ne,f\n"; MappingIterator it = MAPPER.readerFor(Object[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(CSV); assertTrue(it.hasNext()); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/SequenceRecoveryTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/SequenceRecoveryTest.java index bb81394ee..401d4af7c 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/SequenceRecoveryTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/SequenceRecoveryTest.java @@ -43,7 +43,7 @@ public void testSequenceRecovery() throws Exception // can not reuse shared instance because we need: CsvMapper mapper = mapperForCsv(); MappingIterator it = mapper.readerWithSchemaFor(Entry.class) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues( "1,2\n3,invalid\n5,6\n1,2,3,5\n13,-4\ngarbage\n"); Entry entry; diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines15Test.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines15Test.java index 6f1ebe800..7cacfdb4e 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines15Test.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines15Test.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import tools.jackson.databind.ObjectReader; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.ModuleTestBase; import static org.junit.Assert.assertArrayEquals; @@ -35,7 +35,7 @@ public void testSkipEmptyLinesFeature() throws Exception String[][] rows = mapper .readerFor(String[][].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValue(CSV); assertEquals(3, rows.length); String[] row; @@ -56,8 +56,8 @@ public void testSkipEmptyLinesFeature() throws Exception // when wrapped as an array, we'll get array of Lists: rows = mapper.readerFor(String[][].class) - .with(CsvParser.Feature.SKIP_EMPTY_LINES) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValue(CSV); assertEquals(2, rows.length); @@ -84,7 +84,7 @@ public void testCsvWithEmptyLineSkipBlankLinesFeatureDisabled() throws Exception public void testCsvWithEmptyLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_EMPTY_LINE); // empty line is skipped assertArrayEquals(expected( @@ -107,7 +107,7 @@ public void testCsvWithBlankLineSkipBlankLinesFeatureDisabled() throws Exception public void testCsvWithBlankLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_BLANK_LINE); // blank line is skipped assertArrayEquals(expected( @@ -133,7 +133,7 @@ public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureDisabled() throws // when trimming empty lines and/or comments, so test changed for 2.11 public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); // blank/empty lines are skipped assertArrayEquals(expected( @@ -147,8 +147,8 @@ public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabledAndAllowComments() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_EMPTY_LINES) - .with(CsvParser.Feature.ALLOW_COMMENTS) + .with(CsvReadFeature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.ALLOW_COMMENTS) .readValue(CSV_WITH_BLANK_LINE_AND_COMMENT); // blank/empty/comment lines are skipped @@ -171,7 +171,7 @@ public void testCsvWithFirstBlankLineSkipBlankLinesFeatureDisabled() throws Exce public void testCsvWithFirstBlankLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_FIRST_BLANK_LINE); // blank line is skipped assertArrayEquals(expected( @@ -195,7 +195,7 @@ public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureDisabled() throws E public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureEnabled() throws Exception { String[][] rows = mapperForCsvAsArray() - .with(CsvParser.Feature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.SKIP_EMPTY_LINES) .readValue(CSV_WITH_TRAILING_BLANK_LINES); // blank lines are skipped assertArrayEquals(expected( @@ -208,7 +208,7 @@ private ObjectReader mapperForCsvAsArray() { // when wrapped as an array, we'll get array of Lists: return mapperForCsv() .readerFor(String[][].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY); + .with(CsvReadFeature.WRAP_AS_ARRAY); } private String[][] expected(String[]... rowInputs) { diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines191Test.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines191Test.java index 228e301dd..655d69671 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines191Test.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/SkipEmptyLines191Test.java @@ -12,7 +12,7 @@ import tools.jackson.databind.MappingIterator; import tools.jackson.databind.ObjectReader; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.CsvSchema; import tools.jackson.dataformat.csv.ModuleTestBase; @@ -71,7 +71,7 @@ public void testEmptyLines174() throws Exception ObjectReader objectReader = MAPPER .readerFor(Row174.class) - .with(CsvParser.Feature.SKIP_EMPTY_LINES) + .with(CsvReadFeature.SKIP_EMPTY_LINES) .with(MAPPER.schemaFor(Row174.class)); MappingIterator iterator = objectReader.readValues(doc); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserEscapes.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserEscapes.java index 7bac115a5..77ccc5943 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserEscapes.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserEscapes.java @@ -7,8 +7,6 @@ import tools.jackson.databind.MappingIterator; import tools.jackson.dataformat.csv.*; -import tools.jackson.dataformat.csv.CsvSchema; -import tools.jackson.dataformat.csv.ModuleTestBase; public class TestParserEscapes extends ModuleTestBase { @@ -69,9 +67,9 @@ public void testEscaping374() throws Exception CsvSchema schema = CsvSchema.emptySchema().withColumnSeparator(';') .withEscapeChar('\\'); CsvMapper mapper = CsvMapper.builder() - .enable(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS) - .enable(CsvGenerator.Feature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR) - .enable(CsvParser.Feature.WRAP_AS_ARRAY) + .enable(CsvWriteFeature.ALWAYS_QUOTE_STRINGS) + .enable(CsvWriteFeature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR) + .enable(CsvReadFeature.WRAP_AS_ARRAY) .build(); List row1 = Arrays.asList("\"The\"", "foo"); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserNoSchema.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserNoSchema.java index 8b9cf96c2..28c2e0a41 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserNoSchema.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserNoSchema.java @@ -32,7 +32,7 @@ public void testUntypedAsSequence() throws Exception // how `MappingIterator` works MappingIterator it = mapper .readerFor(Object[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(CSV); Object[] row; @@ -64,7 +64,7 @@ public void testUntypedAsObjectArray() throws Exception CsvMapper mapper = mapperForCsv(); // when wrapped as an array, we'll get array of Lists: Object[] rows = mapper.readerFor(Object[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValue( "1,\"xyz\"\n\ntrue,\n" ); @@ -92,7 +92,7 @@ public void testUntypedAsStringArray() throws Exception // when wrapped as an array, we'll get array of Lists: String[][] rows = mapper .readerFor(String[][].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValue("1,\"xyz\"\n\ntrue,\n"); assertEquals(3, rows.length); String[] row; @@ -116,7 +116,7 @@ public void testUntypedViaReadValues() throws Exception { CsvMapper mapper = mapperForCsv(); MappingIterator it = mapper.readerFor(String[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues("1,\"xyz\"\n\ntrue,\n"); assertTrue(it.hasNextValue()); String[] row = it.nextValue(); @@ -173,7 +173,7 @@ public void testUntypedAsSequenceVarLengths() throws Exception // are trying to read Array/Collection values. MappingIterator it = mapper .readerFor(String[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues(CSV); Object[] row; @@ -210,8 +210,8 @@ public void testDelimiterAtBufferBoundary() throws Exception // are trying to read Array/Collection values. String content = col1 + " ," + col2 +"\n" + col2 + "," + col1 + "\n"; MappingIterator it = mapper.readerFor(Object[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) - .with(CsvParser.Feature.TRIM_SPACES) + .with(CsvReadFeature.WRAP_AS_ARRAY) + .with(CsvReadFeature.TRIM_SPACES) .readValues(content); Object[] row; diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserQuotes.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserQuotes.java index 3d662d730..9dfe081b7 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserQuotes.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserQuotes.java @@ -44,7 +44,7 @@ public void testSimpleMultiLine() throws Exception CsvMapper mapper = mapperForCsv(); CsvSchema schema = mapper.schemaFor(AgeName.class); MappingIterator it = mapper.reader(schema).forType(AgeName.class) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues( "-3,\"\"\"Unknown\"\"\"\n\"13\" ,\"Joe \"\"Sixpack\"\" Paxson\""); assertTrue(it.hasNext()); @@ -73,7 +73,7 @@ public void testDisablingQuotes() throws Exception final String RAW_NAME2 = "a\"b"; MappingIterator it = mapper.reader(schema).forType(AgeName.class) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues("38,"+RAW_NAME+"\n" +"27,"+RAW_NAME2+"\n"); assertTrue(it.hasNext()); @@ -98,7 +98,7 @@ public void testDefaultSimpleQuotes() throws Exception // first without array wrapping: MappingIterator it = mapper.readerFor(String[].class) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues("\"te,st\""); assertTrue(it.hasNextValue()); String[] row = it.nextValue(); @@ -113,7 +113,7 @@ public void testDefaultSimpleQuotes() throws Exception // then with array wrapping mapper = mapperForCsv(); it = mapper.readerFor(String[].class) - .with(CsvParser.Feature.WRAP_AS_ARRAY) + .with(CsvReadFeature.WRAP_AS_ARRAY) .readValues("\"te,st\""); assertTrue(it.hasNextValue()); row = it.nextValue(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserStrictQuoting.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserStrictQuoting.java index 9e89f42c3..3e3f72f91 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserStrictQuoting.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserStrictQuoting.java @@ -31,7 +31,7 @@ public void testStrictQuoting() throws Exception CsvMapper mapper = mapperForCsv(); - assertFalse(mapper.tokenStreamFactory().isEnabled(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING)); + assertFalse(mapper.tokenStreamFactory().isEnabled(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING)); CsvSchema schema = mapper.schemaFor(AB.class).withoutHeader(); final AB input = new AB("x", LONG); @@ -43,7 +43,7 @@ public void testStrictQuoting() throws Exception // should be possible to hot-swap // and with strict/optimal, no quoting csv = mapper.writer(schema) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(input); assertEquals(a2q("x,"+LONG), csv.trim()); } diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserWithHeader.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserWithHeader.java index d249cb669..1c062b848 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserWithHeader.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TestParserWithHeader.java @@ -45,7 +45,7 @@ public void testSimpleQuotes() throws Exception CsvMapper mapper = mapperForCsv(); CsvSchema schema = CsvSchema.emptySchema().withHeader(); Entry entry = mapper.readerFor(Entry.class).with(schema) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValue( "name,age,\"cute\" \nLeo,4,true\n"); assertEquals("Leo", entry.name); @@ -58,7 +58,7 @@ public void testSkipFirstDataLine() throws Exception CsvMapper mapper = mapperForCsv(); CsvSchema schema = mapper.schemaFor(Entry.class).withSkipFirstDataRow(true); MappingIterator it = mapper.readerFor(Entry.class).with(schema) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues( "12354\n6,Lila,true"); Entry entry; @@ -94,7 +94,7 @@ public void testLongHeader() throws Exception CsvSchema schema = CsvSchema.emptySchema().withHeader(); CsvParser p = (CsvParser) mapper.reader() .with(schema) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .createParser(CSV); // need to read something to ensure header line is processed assertEquals(JsonToken.START_OBJECT, p.nextToken()); @@ -127,7 +127,7 @@ public void testLongColumnName() throws Exception CsvSchema schema = CsvSchema.emptySchema().withHeader(); CsvParser p = (CsvParser) mapper.reader() .with(schema) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .createParser(CSV); // need to read something to ensure header line is processed assertEquals(JsonToken.START_OBJECT, p.nextToken()); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TrailingCommaCSVTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TrailingCommaCSVTest.java index f68f0aeba..db9f6787e 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/deser/TrailingCommaCSVTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/deser/TrailingCommaCSVTest.java @@ -4,8 +4,8 @@ import tools.jackson.databind.MappingIterator; import tools.jackson.dataformat.csv.CsvMapper; -import tools.jackson.dataformat.csv.CsvParser; import tools.jackson.dataformat.csv.CsvReadException; +import tools.jackson.dataformat.csv.CsvReadFeature; import tools.jackson.dataformat.csv.CsvSchema; import tools.jackson.dataformat.csv.ModuleTestBase; @@ -30,7 +30,7 @@ public void testDisallowTrailingComma() throws Exception MappingIterator it = MAPPER.readerFor(StringPair.class) .with(schema) - .without(CsvParser.Feature.ALLOW_TRAILING_COMMA) + .without(CsvReadFeature.ALLOW_TRAILING_COMMA) .readValues(INPUT); it.nextValue(); @@ -55,7 +55,7 @@ public void testWithTrailingHeaderComma() throws Exception MappingIterator persons = MAPPER .readerFor(Person.class) - .with(CsvParser.Feature.ALLOW_TRAILING_COMMA) + .with(CsvReadFeature.ALLOW_TRAILING_COMMA) .with(schema) . readValues(INPUT); assertTrue(persons.hasNextValue()); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/failing/MappingIteratorEnd119Test.java b/csv/src/test/java/tools/jackson/dataformat/csv/failing/MappingIteratorEnd119Test.java index a0b3b671a..c7854dfe7 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/failing/MappingIteratorEnd119Test.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/failing/MappingIteratorEnd119Test.java @@ -10,7 +10,7 @@ public void testDefaultSimpleQuotes() throws Exception { CsvMapper mapper = mapperForCsv(); MappingIterator it = mapper.readerFor(String[].class) - .without(CsvParser.Feature.WRAP_AS_ARRAY) + .without(CsvReadFeature.WRAP_AS_ARRAY) .readValues("\"te,st\""); assertTrue(it.hasNextValue()); String[] row = it.nextValue(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/filter/StreamingDecoratorsTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/filter/StreamingDecoratorsTest.java index 2113255a6..3a141c18f 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/filter/StreamingDecoratorsTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/filter/StreamingDecoratorsTest.java @@ -17,7 +17,7 @@ public void testInputDecorators() throws IOException final byte[] DOC = utf8("foo,"); final CsvMapper mapper = mapperBuilder( streamFactoryBuilder().inputDecorator(new PrefixInputDecorator(DOC)) - .enable(CsvParser.Feature.WRAP_AS_ARRAY) + .enable(CsvReadFeature.WRAP_AS_ARRAY) .build()) .build(); try (MappingIterator r = mapper.readerFor(String[].class) @@ -47,7 +47,7 @@ public void testOutputDecorators() throws IOException final byte[] DOC = utf8("a,b\n"); final CsvMapper mapper = mapperBuilder( streamFactoryBuilder().outputDecorator(new PrefixOutputDecorator(DOC)) - .enable(CsvParser.Feature.WRAP_AS_ARRAY) + .enable(CsvReadFeature.WRAP_AS_ARRAY) .build()) .build(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorQuotingTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorQuotingTest.java index 28cc527b2..846a14c67 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorQuotingTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorQuotingTest.java @@ -20,21 +20,21 @@ public void testQuotingOfLinefeedsStd() throws Exception String csv; csv = MAPPER.writer(schema) - .without(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .without(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("12\n3", "Foo")); assertEquals("\"12\n3\",Foo\n", csv); csv = MAPPER.writer(schema.withEscapeChar('\\')) - .without(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .without(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("12\n3", "Foo")); assertEquals("\"12\n3\",Foo\n", csv); csv = MAPPER.writer(schema) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("12\n3", "Foo")); assertEquals("\"12\n3\",Foo\n", csv); csv = MAPPER.writer(schema.withEscapeChar('\\')) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("12\n3", "Foo")); assertEquals("\"12\n3\",Foo\n", csv); } @@ -48,25 +48,25 @@ public void testQuotingOfLinefeedsCustom() throws Exception // with loose(default) quoting String csv = MAPPER.writer(schema) - .without(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .without(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(value); assertEquals("\"12-3\",Foo-", csv); // with loose(default) quoting and escape char csv = MAPPER.writer(schema.withEscapeChar('\\')) - .without(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .without(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(value); assertEquals("\"12-3\",Foo-", csv); // with strict/optimal csv = MAPPER.writer(schema) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(value); assertEquals("\"12-3\",Foo-", csv); // with strict/optimal and escape char csv = MAPPER.writer(schema.withEscapeChar('\\')) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(value); assertEquals("\"12-3\",Foo-", csv); } diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorTest.java index 45cc48b92..20ba90101 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/ser/CSVGeneratorTest.java @@ -93,7 +93,7 @@ public void testSimpleExplicit() throws Exception // 14-Jan-2024, tatu: [dataformats-text#45] allow suppressing trailing LF: assertEquals("Silu,Seppala,MALE,AQIDBAU=,false", MAPPER.writer(schema) - .without(CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW) + .without(CsvWriteFeature.WRITE_LINEFEED_AFTER_LAST_ROW) .writeValueAsString(user)); } @@ -115,7 +115,7 @@ public void testWriteHeaders() throws Exception assertEquals("firstName,lastName,gender,verified,userImage\n" +"Barbie,Benton,FEMALE,false,", MAPPER.writer(schema) - .without(CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW) + .without(CsvWriteFeature.WRITE_LINEFEED_AFTER_LAST_ROW) .writeValueAsString(user)); } @@ -240,13 +240,13 @@ public void testForcedQuoting60() throws Exception .addColumn("amount") .build(); String result = mapper.writer(schema) - .with(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS) + .with(CsvWriteFeature.ALWAYS_QUOTE_STRINGS) .writeValueAsString(new Entry("abc", 1.25)); assertEquals("\"abc\",1.25\n", result); // Also, as per [dataformat-csv#81], should be possible to change dynamically result = mapper.writer(schema) - .without(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS) + .without(CsvWriteFeature.ALWAYS_QUOTE_STRINGS) .writeValueAsString(new Entry("xyz", 2.5)); assertEquals("xyz,2.5\n", result); } @@ -260,13 +260,13 @@ public void testForcedQuotingOfBigDecimal() throws Exception .addColumn("enabled") .build(); String result = MAPPER.writer(schema) - .with(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS) + .with(CsvWriteFeature.ALWAYS_QUOTE_STRINGS) .writeValueAsString(new Entry3("abc", BigDecimal.valueOf(2.5), true)); assertEquals("\"abc\",2.5,true\n", result); // Also, as per [dataformat-csv#81], should be possible to change dynamically result = MAPPER.writer(schema) - .without(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS) + .without(CsvWriteFeature.ALWAYS_QUOTE_STRINGS) .writeValueAsString(new Entry3("xyz", BigDecimal.valueOf(1.5), false)); assertEquals("xyz,1.5,false\n", result); } @@ -280,8 +280,8 @@ public void testForcedQuotingWithQuoteEscapedWithBackslash() throws Exception .setEscapeChar('\\') .build(); String result = mapper.writer(schema) - .with(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS) - .with(CsvGenerator.Feature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR) + .with(CsvWriteFeature.ALWAYS_QUOTE_STRINGS) + .with(CsvWriteFeature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR) .writeValueAsString(new Entry("\"abc\"", 1.25)); assertEquals("\"\\\"abc\\\"\",1.25\n", result); } @@ -296,7 +296,7 @@ public void testMissingEscapeCharacterSetting() throws Exception .build(); try { String result = MAPPER.writer(schema) - .with(CsvGenerator.Feature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR) + .with(CsvWriteFeature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR) .writeValueAsString(new Entry("\"abc\"", 1.25)); fail("Should not pass, got: "+result); } catch (CsvWriteException e) { @@ -312,13 +312,13 @@ public void testForcedQuotingEmptyStrings() throws Exception .addColumn("amount") .build(); String result = mapper.writer(schema) - .with(CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS) + .with(CsvWriteFeature.ALWAYS_QUOTE_EMPTY_STRINGS) .writeValueAsString(new Entry("", 1.25)); assertEquals("\"\",1.25\n", result); // Also, as per [dataformat-csv#81], should be possible to change dynamically result = mapper.writer(schema) - .without(CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS) + .without(CsvWriteFeature.ALWAYS_QUOTE_EMPTY_STRINGS) .writeValueAsString(new Entry("", 2.5)); assertEquals(",2.5\n", result); } @@ -334,7 +334,7 @@ public void testQuotingOfCommentCharForFirstColumn() throws Exception // then with strict/optimal csv = MAPPER.writer(schema) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("#123", "Foo")); assertEquals("\"#123\",Foo\n", csv); } @@ -350,7 +350,7 @@ public void testQuotingOfCommentCharForSecondColumn() throws Exception // then with strict/optimal csv = MAPPER.writer(schema) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("123", "#Foo")); assertEquals("123,#Foo\n", csv); } @@ -366,7 +366,7 @@ public void testQuotingOfCommentCharWhenCommentsAreDisabled() throws Exception // then with strict/optimal csv = MAPPER.writer(schema) - .with(CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING) + .with(CsvWriteFeature.STRICT_CHECK_FOR_QUOTING) .writeValueAsString(new IdDesc("#123", "Foo")); assertEquals("#123,Foo\n", csv); } @@ -460,18 +460,18 @@ private void _testForcedQuotingOfNumbers(ObjectWriter w, CsvSchema reorderedSche NumberEntry bean) throws Exception { // First verify with quoting - ObjectWriter w2 = w.with(CsvGenerator.Feature.ALWAYS_QUOTE_NUMBERS); + ObjectWriter w2 = w.with(CsvWriteFeature.ALWAYS_QUOTE_NUMBERS); assertEquals(String.format("%s,\"%s\",%s\n", bean.id, bean.amount, bean.enabled), w2.writeValueAsString(bean)); // And then dynamically disabled variant - ObjectWriter w3 = w2.without(CsvGenerator.Feature.ALWAYS_QUOTE_NUMBERS); + ObjectWriter w3 = w2.without(CsvWriteFeature.ALWAYS_QUOTE_NUMBERS); assertEquals(String.format("%s,%s,%s\n", bean.id, bean.amount, bean.enabled), w3.writeValueAsString(bean)); // And then quoted but reordered to force buffering ObjectWriter w4 = MAPPER.writer(reorderedSchema) - .with(CsvGenerator.Feature.ALWAYS_QUOTE_NUMBERS); + .with(CsvWriteFeature.ALWAYS_QUOTE_NUMBERS); assertEquals(String.format("\"%s\",%s,%s\n", bean.amount, bean.id, bean.enabled), w4.writeValueAsString(bean)); } diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/ser/MultipleWritesTest.java b/csv/src/test/java/tools/jackson/dataformat/csv/ser/MultipleWritesTest.java index c4746a195..475888461 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/ser/MultipleWritesTest.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/ser/MultipleWritesTest.java @@ -8,10 +8,9 @@ import tools.jackson.core.JsonGenerator; import tools.jackson.databind.*; - -import tools.jackson.dataformat.csv.CsvGenerator; import tools.jackson.dataformat.csv.CsvMapper; import tools.jackson.dataformat.csv.CsvSchema; +import tools.jackson.dataformat.csv.CsvWriteFeature; import tools.jackson.dataformat.csv.ModuleTestBase; public class MultipleWritesTest extends ModuleTestBase @@ -90,7 +89,7 @@ public void testWriteValuesWithPOJOs() throws Exception // NOTE! Any form of `flush()` will prevent ability to "remove" trailing LF so... writer = writer .without(SerializationFeature.FLUSH_AFTER_WRITE_VALUE) - .without(CsvGenerator.Feature.WRITE_LINEFEED_AFTER_LAST_ROW); + .without(CsvWriteFeature.WRITE_LINEFEED_AFTER_LAST_ROW); sw = new StringWriter(); try (SequenceWriter seqw = writer.writeValues(sw)) { seqw.write(new Pojo(1, 2, 3)); diff --git a/csv/src/test/java/tools/jackson/dataformat/csv/ser/TestWriterWithMissingValues.java b/csv/src/test/java/tools/jackson/dataformat/csv/ser/TestWriterWithMissingValues.java index b6c3a238a..be9076260 100644 --- a/csv/src/test/java/tools/jackson/dataformat/csv/ser/TestWriterWithMissingValues.java +++ b/csv/src/test/java/tools/jackson/dataformat/csv/ser/TestWriterWithMissingValues.java @@ -38,13 +38,13 @@ public void testWrite_NullSecondColumn() { public void testWrite_NullThirdColumn() { - assertFalse(MAPPER.tokenStreamFactory().isEnabled(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS)); + assertFalse(MAPPER.tokenStreamFactory().isEnabled(CsvWriteFeature.OMIT_MISSING_TAIL_COLUMNS)); String csv = MAPPER.writer(SCHEMA).writeValueAsString( mapOf("timestamp", "2014-03-10T23:32:47+00:00", "value", 42)); assertEquals("\"2014-03-10T23:32:47+00:00\",42,\n", csv); - ObjectWriter w = MAPPER.writer().with(CsvGenerator.Feature.OMIT_MISSING_TAIL_COLUMNS); + ObjectWriter w = MAPPER.writer().with(CsvWriteFeature.OMIT_MISSING_TAIL_COLUMNS); csv = w.with(SCHEMA).writeValueAsString( mapOf("timestamp", "2014-03-10T23:32:47+00:00", "value", 42)); diff --git a/release-notes/VERSION b/release-notes/VERSION index 6edcb6fdf..b123d9eb5 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -20,6 +20,8 @@ implementations) #374: Should verify that escape character set if enabling `CsvGenerator.Feature.ESCAPE_QUOTE_CHAR_WITH_ESCAPE_CHAR` (suggested by @SebastianSolidwork) +#510: JSTEP-8: rename `CsvParser.Feature` as `CsvReadFeature`, + `CsvGenerator.Feature` as `CsvWriteFeature` - Add `XxxMapper.shared()` methods for getting globally shared default instances CSV: