Skip to content

Commit 147f9a7

Browse files
committed
Fixed #240 (well, 2.13 part)
1 parent 97b7c05 commit 147f9a7

File tree

12 files changed

+78
-23
lines changed

12 files changed

+78
-23
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,8 @@ protected void _releaseBuffers() {
979979
*
980980
* @since 2.7
981981
*/
982-
protected void _reportMappingError(String msg) throws JsonProcessingException {
983-
throw CsvMappingException.from(this, msg, _schema);
984-
// throw new JsonGenerationException(msg, this);
982+
protected void _reportMappingError(String msg) throws IOException {
983+
throw CsvWriteException.from(this, msg, _schema);
985984
}
986985

987986
/*

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
* content above minimal decoding, based on {@link CsvSchema}.
88
*
99
* @since 2.9
10+
*
11+
* @deprecated Since 2.13 use sub-class {@link CsvReadException} and {@link CsvWriteException}
12+
* instead
1013
*/
14+
@Deprecated
1115
public class CsvMappingException extends JsonMappingException
1216
{
1317
private static final long serialVersionUID = 1L;
@@ -24,10 +28,12 @@ public CsvMappingException(CsvGenerator gen, String msg, CsvSchema schema) {
2428
_schema = schema;
2529
}
2630

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

36+
@Deprecated // since 2.13: use "CsvWriteException.from()" instead
3137
public static CsvMappingException from(CsvGenerator gen, String msg, CsvSchema schema) {
3238
return new CsvMappingException(gen, msg, schema);
3339
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public enum Feature
104104
ALLOW_COMMENTS(false),
105105

106106
/**
107-
* Feature that allows failing (with a {@link CsvMappingException}) in cases
107+
* Feature that allows failing (with a {@link CsvReadException}) in cases
108108
* where number of column values encountered is less than number of columns
109109
* declared in active schema ("missing columns").
110110
*<p>
@@ -1324,11 +1324,11 @@ protected void _handleEOF() throws JsonParseException {
13241324
*
13251325
* @since 2.9
13261326
*/
1327-
public <T> T _reportCsvMappingError(String msg, Object... args) throws JsonProcessingException {
1327+
public <T> T _reportCsvMappingError(String msg, Object... args) throws IOException {
13281328
if (args.length > 0) {
13291329
msg = String.format(msg, args);
13301330
}
1331-
throw CsvMappingException.from(this, msg, _schema);
1331+
throw CsvReadException.from(this, msg, _schema);
13321332
}
13331333

13341334
public void _reportParsingError(String msg) throws JsonProcessingException {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fasterxml.jackson.dataformat.csv;
2+
3+
/**
4+
* Format-specific exception used to indicate problems regarding low-level
5+
* decoding/parsing issues specific to CSV content;
6+
* usually problems with field-to-column mapping as defined by {@link CsvSchema}.
7+
*<p>
8+
* In Jackson 2.x this type extends
9+
* {@link com.fasterxml.jackson.databind.DatabindException}, but for Jackson 3.0
10+
* will become streaming-level exception
11+
*
12+
* @since 2.13
13+
*/
14+
@SuppressWarnings("deprecation")
15+
public class CsvReadException
16+
extends CsvMappingException
17+
{
18+
private static final long serialVersionUID = 1L;
19+
20+
public CsvReadException(CsvParser p, String msg, CsvSchema schema) {
21+
super(p, msg, schema);
22+
}
23+
24+
public static CsvReadException from(CsvParser p, String msg, CsvSchema schema) {
25+
return new CsvReadException(p, msg, schema);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fasterxml.jackson.dataformat.csv;
2+
3+
/**
4+
* Format-specific exception used to indicate problems regarding low-level
5+
* generation issues specific to CSV content;
6+
* usually problems with field-to-column mapping as defined by {@link CsvSchema}.
7+
*<p>
8+
* In Jackson 2.x this type extends
9+
* {@link com.fasterxml.jackson.databind.DatabindException}, but for Jackson 3.0
10+
* will become streaming-level exception
11+
*
12+
* @since 2.13
13+
*/
14+
@SuppressWarnings("deprecation")
15+
public class CsvWriteException
16+
extends CsvMappingException
17+
{
18+
private static final long serialVersionUID = 1L;
19+
20+
public CsvWriteException(CsvGenerator gen, String msg, CsvSchema schema) {
21+
super(gen, msg, schema);
22+
}
23+
24+
public static CsvWriteException from(CsvGenerator gen, String msg, CsvSchema schema) {
25+
return new CsvWriteException(gen, msg, schema);
26+
}
27+
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.fasterxml.jackson.dataformat.csv.deser;
22

33
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
45
import com.fasterxml.jackson.databind.MappingIterator;
56
import com.fasterxml.jackson.databind.ObjectReader;
6-
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
7-
import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
8-
import com.fasterxml.jackson.dataformat.csv.CsvParser;
9-
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
10-
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
7+
8+
import com.fasterxml.jackson.dataformat.csv.*;
119

1210
/**
1311
* Tests for cases where one more of schema-declared columns is
@@ -113,7 +111,7 @@ public void testFailOnMissingColumns() throws Exception
113111
try {
114112
it.nextValue();
115113
fail("Should not pass");
116-
} catch (CsvMappingException e) {
114+
} catch (CsvReadException e) {
117115
verifyException(e, "Not enough column values");
118116
verifyException(e, "expected 3, found 2");
119117
}
@@ -126,7 +124,7 @@ public void testFailOnMissingColumns() throws Exception
126124
try {
127125
it.nextValue();
128126
fail("Should not pass");
129-
} catch (CsvMappingException e) {
127+
} catch (CsvReadException e) {
130128
verifyException(e, "Not enough column values");
131129
verifyException(e, "expected 3, found 1");
132130
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
1414

1515
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
16-
import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
16+
import com.fasterxml.jackson.dataformat.csv.CsvReadException;
1717
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
1818
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
1919

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

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/GeneratorIgnoreUnknown51Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.fasterxml.jackson.core.JsonGenerator;
99

1010
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
11-
import com.fasterxml.jackson.dataformat.csv.CsvMappingException;
1211
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
12+
import com.fasterxml.jackson.dataformat.csv.CsvWriteException;
1313
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase;
1414

1515
public class GeneratorIgnoreUnknown51Test extends ModuleTestBase
@@ -77,7 +77,7 @@ public void testIgnoreEmbeddedObject() throws Exception
7777
try {
7878
mapper.writer(schema).writeValue(sw, myClass);
7979
fail("Should not pass");
80-
} catch (CsvMappingException e) {
80+
} catch (CsvWriteException e) {
8181
verifyException(e, "CSV generator does not support");
8282
verifyException(e, "nested Objects");
8383
}

properties/src/main/java/com/fasterxml/jackson/dataformat/javaprop/impl/WriterBackedGenerator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public Object getOutputTarget() {
7575
/**********************************************************
7676
*/
7777

78-
@SuppressWarnings("deprecation")
7978
@Override
8079
public void close() throws IOException
8180
{
@@ -95,7 +94,6 @@ public void close() throws IOException
9594
_releaseBuffers();
9695
}
9796

98-
@SuppressWarnings("deprecation")
9997
@Override
10098
public void flush() throws IOException
10199
{

release-notes/VERSION-2.x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Modules:
1010

1111
2.13.0 (not yet released)
1212

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

1515
2.12.1 (08-Jan-2021)
1616

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLFactoryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public YAMLFactoryBuilder configure(YAMLGenerator.Feature f, boolean state) {
104104
/**
105105
* Method for specifying either custom {@link StringQuotingChecker}
106106
* to use instead of default one, or, that default one (see
107-
* {@link StringQuotingChecker.Default#instance()}) is to be used
107+
* {@code StringQuotingChecker.Default.instance()}) is to be used
108108
* (when passing {@code null}
109109
*
110110
* @param sqc Checker to use (if non-null), or {@code null} to use the
111-
* default one (see {@link StringQuotingChecker.Default#instance()})
111+
* default one (see {@code StringQuotingChecker.Default.instance()})
112112
*
113113
* @return This builder instance, to allow chaining
114114
*/

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/filter/StreamingDecoratorsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void testInputDecorators() throws IOException
3131
assertEquals("mum", value.get("secret"));
3232
}
3333

34-
@SuppressWarnings("unchecked")
3534
public void testOutputDecorators() throws IOException
3635
{
3736
final String PREFIX = "///////";

0 commit comments

Comments
 (0)