Skip to content

Commit e68dacd

Browse files
committed
Fix #108
1 parent eaa1d14 commit e68dacd

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public enum Feature
8989
*/
9090
ALLOW_TRAILING_COMMA(true),
9191

92+
/**
93+
* Feature that allows accepting "hash comments" by default, similar to
94+
* {@link CsvSchema#withAllowComments(boolean)}. If enabled, such comments
95+
* are by default allowed on all columns of all documents.
96+
*
97+
* @since 2.10
98+
*/
99+
ALLOW_COMMENTS(false),
100+
92101
/**
93102
* Feature that allows failing (with a {@link CsvMappingException}) in cases
94103
* where number of column values encountered is less than number of columns

csv/src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvDecoder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,15 @@ public class CsvDecoder
256256

257257
public CsvDecoder(CsvParser owner, IOContext ctxt, Reader r, CsvSchema schema, TextBuffer textBuffer,
258258
int stdFeatures, int csvFeatures)
259-
// boolean autoCloseInput, boolean trimSpaces)
260259
{
261260
_owner = owner;
262261
_ioContext = ctxt;
263262
_inputSource = r;
264263
_textBuffer = textBuffer;
265264
_autoCloseInput = JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledIn(stdFeatures);
266-
_allowComments = JsonParser.Feature.ALLOW_YAML_COMMENTS.enabledIn(stdFeatures);
265+
@SuppressWarnings("deprecation")
266+
final boolean legacy = JsonParser.Feature.ALLOW_YAML_COMMENTS.enabledIn(stdFeatures);
267+
_allowComments = legacy | CsvParser.Feature.ALLOW_COMMENTS.enabledIn(csvFeatures);
267268
_trimSpaces = CsvParser.Feature.TRIM_SPACES.enabledIn(csvFeatures);
268269
_inputBuffer = ctxt.allocTokenBuffer();
269270
_bufferRecyclable = true; // since we allocated it

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ModuleTestBase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ protected ModuleTestBase() { }
8787
/* Helper methods, setup
8888
/**********************************************************************
8989
*/
90-
90+
9191
protected CsvMapper mapperForCsv()
9292
{
9393
return CsvMapper.builder().build();
9494
}
95+
96+
protected CsvMapper.Builder mapperBuilder()
97+
{
98+
return CsvMapper.builder();
99+
}
95100

96101
/*
97102
/**********************************************************

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/CommentsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.Map;
44

5-
import com.fasterxml.jackson.core.JsonParser;
65
import com.fasterxml.jackson.databind.MappingIterator;
76
import com.fasterxml.jackson.dataformat.csv.*;
87

@@ -123,9 +122,10 @@ public void testCommentsWithHeaderRow() throws Exception
123122
// Alternate test to ensure comments may be enabled
124123
public void testSimpleCommentsWithDefaultProp() throws Exception
125124
{
126-
CsvMapper mapper = mapperForCsv();
127-
mapper.enable(JsonParser.Feature.ALLOW_YAML_COMMENTS);
128-
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
125+
CsvMapper mapper = mapperBuilder()
126+
.enable(CsvParser.Feature.ALLOW_COMMENTS) // since 2.10
127+
.enable(CsvParser.Feature.WRAP_AS_ARRAY)
128+
.build();
129129
final String CSV = "# comment!\na,b\n";
130130

131131
MappingIterator<String[]> it = mapper.readerFor(String[].class)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Modules:
1212

1313
#101: Use latest SnakeYAML version 1.23 and get rid of deprecated methods
1414
(contributed by Andrey S)
15+
#108: Add new `CsvParser.Feature.ALLOW_COMMENTS` to replace deprecated
16+
`JsonParser.Feature.ALLOW_YAML_COMMENTS`
1517

1618
2.9.7 (not yet released)
1719

0 commit comments

Comments
 (0)