Skip to content

Commit 3d845a3

Browse files
committed
Try to reduce usage of JsonMappingException (to prepare for #2828)
1 parent 0793e87 commit 3d845a3

23 files changed

+52
-69
lines changed

src/test/java/com/fasterxml/jackson/databind/contextual/TestContextualDeserialization.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public StringValue deserialize(JsonParser jp, DeserializationContext ctxt) throw
107107
@Override
108108
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
109109
BeanProperty property)
110-
throws JsonMappingException
111110
{
112111
String name = (property == null) ? "NULL" : property.getName();
113112
return new MyContextualDeserializer(name);
@@ -137,7 +136,6 @@ public StringValue deserialize(JsonParser jp, DeserializationContext ctxt) throw
137136
@Override
138137
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
139138
BeanProperty property)
140-
throws JsonMappingException
141139
{
142140
Name ann = property.getAnnotation(Name.class);
143141
if (ann == null) {

src/test/java/com/fasterxml/jackson/databind/contextual/TestContextualKeyTypes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi
4545

4646
@Override
4747
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
48-
throws JsonMappingException
4948
{
5049
return new ContextualKeySerializer(_prefix+":");
5150
}
@@ -70,7 +69,7 @@ public Object deserializeKey(String key, DeserializationContext ctxt)
7069

7170
@Override
7271
public KeyDeserializer createContextual(DeserializationContext ctxt,
73-
BeanProperty property) throws JsonMappingException
72+
BeanProperty property)
7473
{
7574
return new ContextualDeser((property == null) ? "ROOT" : property.getName());
7675
}

src/test/java/com/fasterxml/jackson/databind/contextual/TestContextualSerialization.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi
134134

135135
@Override
136136
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
137-
throws JsonMappingException
138137
{
139138
String prefix = "UNKNOWN";
140139
Prefix ann = null;
@@ -174,7 +173,6 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi
174173

175174
@Override
176175
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
177-
throws JsonMappingException
178176
{
179177
return new ContextualAndResolvable(isResolved, isContextual+1);
180178
}
@@ -205,7 +203,6 @@ public void serialize(String value, JsonGenerator g, SerializerProvider provider
205203

206204
@Override
207205
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
208-
throws JsonMappingException
209206
{
210207
if (property == null) {
211208
return new AccumulatingContextual(desc+"/ROOT");

src/test/java/com/fasterxml/jackson/databind/contextual/TestContextualWithAnnDeserializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public StringValue deserialize(JsonParser p, DeserializationContext ctxt) throws
5454
@Override
5555
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
5656
BeanProperty property)
57-
throws JsonMappingException
5857
{
5958
Name ann = property.getAnnotation(Name.class);
6059
if (ann == null) {

src/test/java/com/fasterxml/jackson/databind/convert/CoerceToBooleanTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
import com.fasterxml.jackson.core.JsonParser;
1111
import com.fasterxml.jackson.core.JsonToken;
1212

13-
import com.fasterxml.jackson.databind.BaseMapTest;
14-
import com.fasterxml.jackson.databind.DeserializationFeature;
15-
import com.fasterxml.jackson.databind.JsonMappingException;
16-
import com.fasterxml.jackson.databind.MapperFeature;
17-
import com.fasterxml.jackson.databind.ObjectMapper;
18-
import com.fasterxml.jackson.databind.ObjectReader;
13+
import com.fasterxml.jackson.databind.*;
1914
import com.fasterxml.jackson.databind.cfg.CoercionAction;
2015
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
2116
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
@@ -99,7 +94,7 @@ public void testEmptyStringFailForBooleanPrimitive() throws IOException
9994
try {
10095
reader.readValue(aposToQuotes("{'booleanValue':''}"));
10196
fail("Expected failure for boolean + empty String");
102-
} catch (JsonMappingException e) {
97+
} catch (MismatchedInputException e) {
10398
verifyException(e, "Cannot coerce `null` to `boolean`");
10499
verifyException(e, "FAIL_ON_NULL_FOR_PRIMITIVES");
105100
}

src/test/java/com/fasterxml/jackson/databind/deser/TestBeanDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public Issue476Deserializer(BeanDeserializer src) {
113113

114114
@Override
115115
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
116-
BeanProperty property) throws JsonMappingException {
116+
BeanProperty property) {
117117
propCount++;
118118
return this;
119119
}

src/test/java/com/fasterxml/jackson/databind/deser/TestConcurrency.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
*/
1212
public class TestConcurrency extends BaseMapTest
1313
{
14-
/*
15-
/**********************************************
16-
/* Helper beans
17-
/**********************************************
18-
*/
19-
2014
@JsonDeserialize(using=CustomBeanDeserializer.class)
2115
static class Bean
2216
{
@@ -51,7 +45,7 @@ public Bean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExc
5145
}
5246

5347
@Override
54-
public void resolve(DeserializationContext ctxt) throws JsonMappingException
48+
public void resolve(DeserializationContext ctxt)
5549
{
5650
try {
5751
Thread.sleep(100L);

src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public Bean375Outer deserialize(JsonParser p, DeserializationContext ctxt)
180180
}
181181
@Override
182182
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
183-
throws JsonMappingException {
183+
{
184184
return new Bean375OuterDeserializer(property);
185185
}
186186
}
@@ -211,7 +211,7 @@ public Bean375Inner deserialize(JsonParser p, DeserializationContext ctxt)
211211

212212
@Override
213213
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
214-
throws JsonMappingException {
214+
{
215215
if (property != null) {
216216
Negative n = property.getAnnotation(Negative.class);
217217
if (n != null) {

src/test/java/com/fasterxml/jackson/databind/deser/creators/EnumCreatorTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.fasterxml.jackson.databind.*;
1313
import com.fasterxml.jackson.databind.deser.Deserializers;
1414
import com.fasterxml.jackson.databind.deser.std.EnumDeserializer;
15+
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
1516
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
1617
import com.fasterxml.jackson.databind.module.SimpleModule;
1718

@@ -103,7 +104,8 @@ protected enum TestEnum324
103104
static class DelegatingDeserializers extends Deserializers.Base
104105
{
105106
@Override
106-
public JsonDeserializer<?> findEnumDeserializer(final Class<?> type, final DeserializationConfig config, final BeanDescription beanDesc) throws JsonMappingException {
107+
public JsonDeserializer<?> findEnumDeserializer(final Class<?> type, final DeserializationConfig config, final BeanDescription beanDesc)
108+
{
107109
final Collection<AnnotatedMethod> factoryMethods = beanDesc.getFactoryMethods();
108110
if (factoryMethods != null) {
109111
for (AnnotatedMethod am : factoryMethods) {
@@ -255,7 +257,7 @@ public void testExceptionFromCreator() throws Exception
255257
try {
256258
/*TestEnum324 e =*/ MAPPER.readValue(quote("xyz"), TestEnum324.class);
257259
fail("Should throw exception");
258-
} catch (JsonMappingException e) {
260+
} catch (ValueInstantiationException e) {
259261
verifyException(e, "foobar");
260262
}
261263
}

src/test/java/com/fasterxml/jackson/databind/deser/creators/NullValueViaCreatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.core.*;
88
import com.fasterxml.jackson.databind.*;
99
import com.fasterxml.jackson.databind.deser.*;
10+
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
1011

1112
public class NullValueViaCreatorTest extends BaseMapTest
1213
{
@@ -41,7 +42,6 @@ protected static class ContainerDeserializerResolver extends Deserializers.Base
4142
@Override
4243
public JsonDeserializer<?> findBeanDeserializer(JavaType type,
4344
DeserializationConfig config, BeanDescription beanDesc)
44-
throws JsonMappingException
4545
{
4646
if (!Contained.class.isAssignableFrom(type.getRawClass())) {
4747
return null;
@@ -108,7 +108,7 @@ public void testCreatorReturningNull() throws IOException {
108108
try {
109109
objectMapper.readValue(json, JsonEntity.class);
110110
fail("Should not have succeeded");
111-
} catch (JsonMappingException e) {
111+
} catch (ValueInstantiationException e) {
112112
verifyException(e, "JSON creator returned null");
113113
}
114114
}

src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCustomValueInstDefaults.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* and {@link PropertyValueBuffer#getParameter(SettableBeanProperty)} methods.
2020
*/
2121
@SuppressWarnings("serial")
22-
public class TestCustomValueInstDefaults extends BaseTest
22+
public class TestCustomValueInstDefaults
23+
extends BaseMapTest
2324
{
2425
static class Bucket
2526
{
@@ -119,10 +120,9 @@ static class BucketInstantiator extends StdValueInstantiator
119120
}
120121

121122
@Override
122-
public Object createFromObjectWith(
123-
DeserializationContext ctxt,
124-
SettableBeanProperty[] props,
125-
PropertyValueBuffer buffer) throws JsonMappingException
123+
public Object createFromObjectWith(DeserializationContext ctxt,
124+
SettableBeanProperty[] props, PropertyValueBuffer buffer)
125+
throws IOException
126126
{
127127
int a = Bucket.DEFAULT_A;
128128
int b = Bucket.DEFAULT_B;
@@ -153,10 +153,9 @@ static class BigBucketInstantiator extends StdValueInstantiator
153153
}
154154

155155
@Override
156-
public Object createFromObjectWith(
157-
DeserializationContext ctxt,
158-
SettableBeanProperty[] props,
159-
PropertyValueBuffer buffer) throws JsonMappingException
156+
public Object createFromObjectWith(DeserializationContext ctxt,
157+
SettableBeanProperty[] props, PropertyValueBuffer buffer)
158+
throws IOException
160159
{
161160
int i01 = BigBucket.DEFAULT_I;
162161
int i02 = BigBucket.DEFAULT_I;

src/test/java/com/fasterxml/jackson/databind/exc/ExceptionSerializationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ public void testIgnorals() throws Exception
113113
}
114114

115115
// [databind#1368]
116-
public void testJsonMappingExceptionSerialization() throws IOException {
116+
public void testDatabindExceptionSerialization() throws IOException {
117117
Exception e = null;
118118
// cant deserialize due to unexpected constructor
119119
try {
120120
MAPPER.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class );
121121
fail("Should not pass");
122-
} catch (JsonMappingException e0) {
122+
} catch (MismatchedInputException e0) {
123123
verifyException(e0, "cannot deserialize from Object");
124124
e = e0;
125125
}

src/test/java/com/fasterxml/jackson/databind/exc/TestExceptionHandlingWithDefaultDeserialization.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import java.io.IOException;
88

9-
public class TestExceptionHandlingWithDefaultDeserialization extends BaseMapTest
9+
public class TestExceptionHandlingWithDefaultDeserialization
10+
extends BaseMapTest
1011
{
1112
static class Foo {
1213
private Bar bar;
@@ -38,7 +39,7 @@ public String getQux() {
3839
}
3940
}
4041

41-
public void testShouldThrowJsonMappingExceptionWithPathReference() throws IOException {
42+
public void testShouldThrowExceptionWithPathReference() throws IOException {
4243
// given
4344
ObjectMapper mapper = new ObjectMapper();
4445
String input = "{\"bar\":{\"baz\":{qux:\"quxValue\"))}";

src/test/java/com/fasterxml/jackson/databind/exc/TestExceptionHandlingWithJsonCreatorDeserialization.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import java.io.IOException;
1010

11-
public class TestExceptionHandlingWithJsonCreatorDeserialization extends BaseMapTest
11+
public class TestExceptionHandlingWithJsonCreatorDeserialization
12+
extends BaseMapTest
1213
{
1314
static class Foo {
1415
private Bar bar;
@@ -49,7 +50,7 @@ public String getQux() {
4950
}
5051
}
5152

52-
public void testShouldThrowJsonMappingExceptionWithPathReference() throws IOException {
53+
public void testShouldThrowExceptionWithPathReference() throws IOException {
5354
// given
5455
ObjectMapper mapper = new ObjectMapper();
5556
String input = "{\"bar\":{\"baz\":{qux:\"quxValue\"))}";

src/test/java/com/fasterxml/jackson/databind/jsonschema/NewSchemaTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void optionalProperty(BeanProperty prop) throws JsonMappingException {
130130

131131
@Override
132132
public void optionalProperty(String name, JsonFormatVisitable handler,
133-
JavaType propertyTypeHint) throws JsonMappingException { }
133+
JavaType propertyTypeHint) { }
134134

135135
private void _visit(BeanProperty prop) throws JsonMappingException
136136
{
@@ -315,7 +315,7 @@ public void optionalProperty(BeanProperty prop) throws JsonMappingException {
315315
ser.acceptJsonFormatVisitor(new JsonFormatVisitorWrapper.Base() {
316316
@Override
317317
public JsonNumberFormatVisitor expectNumberFormat(
318-
JavaType t) throws JsonMappingException {
318+
JavaType t) {
319319
return new JsonNumberFormatVisitor() {
320320
@Override
321321
public void format(JsonValueFormat format) {
@@ -333,7 +333,7 @@ public void numberType(NumberType numberType) {
333333
}
334334

335335
@Override
336-
public JsonIntegerFormatVisitor expectIntegerFormat(JavaType t) throws JsonMappingException {
336+
public JsonIntegerFormatVisitor expectIntegerFormat(JavaType t) {
337337
return new JsonIntegerFormatVisitor() {
338338
@Override
339339
public void format(JsonValueFormat format) {

src/test/java/com/fasterxml/jackson/databind/jsontype/ext/TestPropertyCreatorSubtypesExternalPropertyMissingProperty.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ public void testDeserializationMissing() throws Exception {
177177
checkOrangeBoxNull(BOX_READER_PASS, orangeBoxMissingJson);
178178
checkAppleBoxNull(BOX_READER_PASS, appleBoxMissingJson);
179179

180-
checkBoxJsonMappingException(BOX_READER_FAIL, orangeBoxMissingJson);
181-
checkBoxJsonMappingException(BOX_READER_FAIL, appleBoxMissingJson);
180+
checkBoxException(BOX_READER_FAIL, orangeBoxMissingJson);
181+
checkBoxException(BOX_READER_FAIL, appleBoxMissingJson);
182182
}
183183

184184
private void checkOrangeBox(ObjectReader reader) throws Exception {
@@ -233,7 +233,7 @@ private void checkAppleBoxNull(ObjectReader reader, String json) throws Exceptio
233233
assertNull(deserAppleBox.getFruit());
234234
}
235235

236-
private void checkBoxJsonMappingException(ObjectReader reader, String json) throws Exception {
236+
private void checkBoxException(ObjectReader reader, String json) throws Exception {
237237
try {
238238
reader.readValue(json);
239239
fail("Should not pass");

src/test/java/com/fasterxml/jackson/databind/jsontype/ext/TestSubtypesExternalPropertyMissingProperty.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ public void testDeserializationMissing() throws Exception {
167167
checkAppleBoxNull(r, appleBoxMissingJson);
168168

169169
r = READER.with(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY);
170-
checkBoxJsonMappingException(r, orangeBoxMissingJson);
171-
checkBoxJsonMappingException(r, appleBoxMissingJson);
170+
checkBoxDatabindException(r, orangeBoxMissingJson);
171+
checkBoxDatabindException(r, appleBoxMissingJson);
172172
}
173173

174174
/**
@@ -177,12 +177,12 @@ public void testDeserializationMissing() throws Exception {
177177
@Test
178178
public void testDeserializationMissingRequired() throws Exception {
179179
ObjectReader r = READER.without(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY);
180-
checkReqBoxJsonMappingException(r, orangeBoxMissingJson);
181-
checkReqBoxJsonMappingException(r, appleBoxMissingJson);
180+
checkReqBoxDatabindException(r, orangeBoxMissingJson);
181+
checkReqBoxDatabindException(r, appleBoxMissingJson);
182182

183183
r = READER.with(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY);
184-
checkReqBoxJsonMappingException(r, orangeBoxMissingJson);
185-
checkReqBoxJsonMappingException(r, appleBoxMissingJson);
184+
checkReqBoxDatabindException(r, orangeBoxMissingJson);
185+
checkReqBoxDatabindException(r, appleBoxMissingJson);
186186
}
187187

188188
private void checkOrangeBox(ObjectReader r) throws Exception {
@@ -237,7 +237,7 @@ private void checkAppleBoxNull(ObjectReader r, String json) throws Exception {
237237
assertNull(deserAppleBox.fruit);
238238
}
239239

240-
private void checkBoxJsonMappingException(ObjectReader r, String json) throws Exception {
240+
private void checkBoxDatabindException(ObjectReader r, String json) throws Exception {
241241
try {
242242
r.forType(Box.class).readValue(json);
243243
fail("Should not pass");
@@ -246,7 +246,7 @@ private void checkBoxJsonMappingException(ObjectReader r, String json) throws Ex
246246
}
247247
}
248248

249-
private void checkReqBoxJsonMappingException(ObjectReader r, String json) throws Exception {
249+
private void checkReqBoxDatabindException(ObjectReader r, String json) throws Exception {
250250
try {
251251
r.forType(ReqBox.class).readValue(json, ReqBox.class);
252252
fail("Should not pass");

src/test/java/com/fasterxml/jackson/databind/module/SimpleModuleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p
4545
}
4646

4747
@Override
48-
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
48+
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
4949
return null;
5050
}
5151
}
@@ -79,7 +79,7 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p
7979
}
8080

8181
@Override
82-
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
82+
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
8383
return null;
8484
}
8585
}

0 commit comments

Comments
 (0)