Skip to content

Commit

Permalink
Fixed #240 (well, 2.13 part)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 23, 2021
1 parent 97b7c05 commit 147f9a7
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,8 @@ protected void _releaseBuffers() {
*
* @since 2.7
*/
protected void _reportMappingError(String msg) throws JsonProcessingException {
throw CsvMappingException.from(this, msg, _schema);
// throw new JsonGenerationException(msg, this);
protected void _reportMappingError(String msg) throws IOException {
throw CsvWriteException.from(this, msg, _schema);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* content above minimal decoding, based on {@link CsvSchema}.
*
* @since 2.9
*
* @deprecated Since 2.13 use sub-class {@link CsvReadException} and {@link CsvWriteException}
* instead
*/
@Deprecated
public class CsvMappingException extends JsonMappingException
{
private static final long serialVersionUID = 1L;
Expand All @@ -24,10 +28,12 @@ public CsvMappingException(CsvGenerator gen, String msg, CsvSchema schema) {
_schema = schema;
}

@Deprecated // since 2.13: use "CsvReadException.from()" instead
public static CsvMappingException from(CsvParser p, String msg, CsvSchema schema) {
return new CsvMappingException(p, msg, schema);
}

@Deprecated // since 2.13: use "CsvWriteException.from()" instead
public static CsvMappingException from(CsvGenerator gen, String msg, CsvSchema schema) {
return new CsvMappingException(gen, msg, schema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public enum Feature
ALLOW_COMMENTS(false),

/**
* Feature that allows failing (with a {@link CsvMappingException}) in cases
* Feature that allows failing (with a {@link CsvReadException}) in cases
* where number of column values encountered is less than number of columns
* declared in active schema ("missing columns").
*<p>
Expand Down Expand Up @@ -1324,11 +1324,11 @@ protected void _handleEOF() throws JsonParseException {
*
* @since 2.9
*/
public <T> T _reportCsvMappingError(String msg, Object... args) throws JsonProcessingException {
public <T> T _reportCsvMappingError(String msg, Object... args) throws IOException {
if (args.length > 0) {
msg = String.format(msg, args);
}
throw CsvMappingException.from(this, msg, _schema);
throw CsvReadException.from(this, msg, _schema);
}

public void _reportParsingError(String msg) throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fasterxml.jackson.dataformat.csv;

/**
* Format-specific exception used to indicate problems regarding low-level
* decoding/parsing issues specific to CSV content;
* usually problems with field-to-column mapping as defined by {@link CsvSchema}.
*<p>
* In Jackson 2.x this type extends
* {@link com.fasterxml.jackson.databind.DatabindException}, but for Jackson 3.0
* will become streaming-level exception
*
* @since 2.13
*/
@SuppressWarnings("deprecation")
public class CsvReadException
extends CsvMappingException
{
private static final long serialVersionUID = 1L;

public CsvReadException(CsvParser p, String msg, CsvSchema schema) {
super(p, msg, schema);
}

public static CsvReadException from(CsvParser p, String msg, CsvSchema schema) {
return new CsvReadException(p, msg, schema);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fasterxml.jackson.dataformat.csv;

/**
* Format-specific exception used to indicate problems regarding low-level
* generation issues specific to CSV content;
* usually problems with field-to-column mapping as defined by {@link CsvSchema}.
*<p>
* In Jackson 2.x this type extends
* {@link com.fasterxml.jackson.databind.DatabindException}, but for Jackson 3.0
* will become streaming-level exception
*
* @since 2.13
*/
@SuppressWarnings("deprecation")
public class CsvWriteException
extends CsvMappingException
{
private static final long serialVersionUID = 1L;

public CsvWriteException(CsvGenerator gen, String msg, CsvSchema schema) {
super(gen, msg, schema);
}

public static CsvWriteException from(CsvGenerator gen, String msg, CsvSchema schema) {
return new CsvWriteException(gen, msg, schema);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
import com.fasterxml.jackson.dataformat.csv.CsvParser;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;

import com.fasterxml.jackson.dataformat.csv.*;

/**
* Tests for cases where one more of schema-declared columns is
Expand Down Expand Up @@ -113,7 +111,7 @@ public void testFailOnMissingColumns() throws Exception
try {
it.nextValue();
fail("Should not pass");
} catch (CsvMappingException e) {
} catch (CsvReadException e) {
verifyException(e, "Not enough column values");
verifyException(e, "expected 3, found 2");
}
Expand All @@ -126,7 +124,7 @@ public void testFailOnMissingColumns() throws Exception
try {
it.nextValue();
fail("Should not pass");
} catch (CsvMappingException e) {
} catch (CsvReadException e) {
verifyException(e, "Not enough column values");
verifyException(e, "expected 3, found 1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
import com.fasterxml.jackson.dataformat.csv.CsvReadException;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;

Expand Down Expand Up @@ -114,7 +114,8 @@ public void testSchemaWithJsonViewDeserializationFail() throws Exception
try {
MAPPER.readerFor(Bean.class).with(schema).withView(ViewB.class).readValue(input);
fail();
} catch (CsvMappingException ignore) {
} catch (CsvReadException e) {
verifyException(e, "Too many entries: expected at most 2");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.fasterxml.jackson.core.JsonGenerator;

import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.fasterxml.jackson.dataformat.csv.CsvWriteException;
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;

public class GeneratorIgnoreUnknown51Test extends ModuleTestBase
Expand Down Expand Up @@ -77,7 +77,7 @@ public void testIgnoreEmbeddedObject() throws Exception
try {
mapper.writer(schema).writeValue(sw, myClass);
fail("Should not pass");
} catch (CsvMappingException e) {
} catch (CsvWriteException e) {
verifyException(e, "CSV generator does not support");
verifyException(e, "nested Objects");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public Object getOutputTarget() {
/**********************************************************
*/

@SuppressWarnings("deprecation")
@Override
public void close() throws IOException
{
Expand All @@ -95,7 +94,6 @@ public void close() throws IOException
_releaseBuffers();
}

@SuppressWarnings("deprecation")
@Override
public void flush() throws IOException
{
Expand Down
2 changes: 1 addition & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Modules:

2.13.0 (not yet released)

No changes since 2.12
#240: (csv) Split `CsvMappingException` into `CsvReadException`/`CsvWriteException`

2.12.1 (08-Jan-2021)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public YAMLFactoryBuilder configure(YAMLGenerator.Feature f, boolean state) {
/**
* Method for specifying either custom {@link StringQuotingChecker}
* to use instead of default one, or, that default one (see
* {@link StringQuotingChecker.Default#instance()}) is to be used
* {@code StringQuotingChecker.Default.instance()}) is to be used
* (when passing {@code null}
*
* @param sqc Checker to use (if non-null), or {@code null} to use the
* default one (see {@link StringQuotingChecker.Default#instance()})
* default one (see {@code StringQuotingChecker.Default.instance()})
*
* @return This builder instance, to allow chaining
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void testInputDecorators() throws IOException
assertEquals("mum", value.get("secret"));
}

@SuppressWarnings("unchecked")
public void testOutputDecorators() throws IOException
{
final String PREFIX = "///////";
Expand Down

0 comments on commit 147f9a7

Please sign in to comment.