Skip to content

Commit

Permalink
Fix #108
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 26, 2018
1 parent eaa1d14 commit e68dacd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public enum Feature
*/
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.
*
* @since 2.10
*/
ALLOW_COMMENTS(false),

/**
* Feature that allows failing (with a {@link CsvMappingException}) in cases
* where number of column values encountered is less than number of columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ public class CsvDecoder

public CsvDecoder(CsvParser owner, IOContext ctxt, Reader r, CsvSchema schema, TextBuffer textBuffer,
int stdFeatures, int csvFeatures)
// boolean autoCloseInput, boolean trimSpaces)
{
_owner = owner;
_ioContext = ctxt;
_inputSource = r;
_textBuffer = textBuffer;
_autoCloseInput = JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledIn(stdFeatures);
_allowComments = JsonParser.Feature.ALLOW_YAML_COMMENTS.enabledIn(stdFeatures);
@SuppressWarnings("deprecation")
final boolean legacy = JsonParser.Feature.ALLOW_YAML_COMMENTS.enabledIn(stdFeatures);
_allowComments = legacy | CsvParser.Feature.ALLOW_COMMENTS.enabledIn(csvFeatures);
_trimSpaces = CsvParser.Feature.TRIM_SPACES.enabledIn(csvFeatures);
_inputBuffer = ctxt.allocTokenBuffer();
_bufferRecyclable = true; // since we allocated it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ protected ModuleTestBase() { }
/* Helper methods, setup
/**********************************************************************
*/

protected CsvMapper mapperForCsv()
{
return CsvMapper.builder().build();
}

protected CsvMapper.Builder mapperBuilder()
{
return CsvMapper.builder();
}

/*
/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Map;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.*;

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

MappingIterator<String[]> it = mapper.readerFor(String[].class)
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Modules:

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

2.9.7 (not yet released)

Expand Down

0 comments on commit e68dacd

Please sign in to comment.