Skip to content

Commit 516c91f

Browse files
committed
Completed eradication of JsonMappingException from tests (which can be done for 2.x); now moving to 3.0 side
1 parent db3aefb commit 516c91f

20 files changed

+79
-120
lines changed

Diff for: src/test/java/com/fasterxml/jackson/databind/TestRootName.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,15 @@ public void testReconfiguringOfWrapping() throws Exception
145145
result = mapper.readerFor(Bean.class).with(DeserializationFeature.UNWRAP_ROOT_VALUE)
146146
.readValue(jsonUnwrapped);
147147
fail("Should have failed");
148-
} catch (JsonMappingException e) {
148+
} catch (MismatchedInputException e) {
149149
verifyException(e, "Root name ('a')");
150150
}
151151
// except wrapping may be expected:
152152
result = mapper.readerFor(Bean.class).with(DeserializationFeature.UNWRAP_ROOT_VALUE)
153153
.readValue(jsonWrapped);
154154
assertNotNull(result);
155155
}
156-
157-
// [JACKSON-764]
156+
158157
public void testRootUsingExplicitConfig() throws Exception
159158
{
160159
ObjectMapper mapper = new ObjectMapper();

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/CyclicTypesDeserTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
55
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
67

78
/**
89
* Simple unit tests to verify that it is possible to handle
@@ -102,7 +103,7 @@ public void testIgnoredCycle() throws Exception
102103
try {
103104
MAPPER.writeValueAsString(self1);
104105
fail("Should fail with direct self-ref");
105-
} catch (JsonMappingException e) {
106+
} catch (InvalidDefinitionException e) {
106107
verifyException(e, "Direct self-reference");
107108
}
108109

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/IncludeWithDeserTest.java

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.fasterxml.jackson.databind.deser;
22

3-
import com.fasterxml.jackson.annotation.JsonAnySetter;
4-
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
5-
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
6-
import com.fasterxml.jackson.annotation.JsonProperty;
7-
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
8-
import com.fasterxml.jackson.databind.BaseMapTest;
9-
import com.fasterxml.jackson.databind.DeserializationFeature;
10-
import com.fasterxml.jackson.databind.JsonMappingException;
11-
import com.fasterxml.jackson.databind.ObjectMapper;
12-
import com.fasterxml.jackson.databind.ObjectReader;
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.databind.exc.IgnoredPropertyException;
7+
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
138

149
import java.util.Arrays;
1510
import java.util.HashMap;
@@ -138,15 +133,15 @@ public void testIncludeIgnoredAndUnrecognizedField() throws Exception
138133
try {
139134
r.readValue(aposToQuotes("{'x':3, 'y': 4, 'z': 5}"));
140135
fail("Should fail");
141-
} catch (JsonMappingException e) {
136+
} catch (IgnoredPropertyException e) {
142137
verifyException(e, "Ignored field");
143138
}
144139

145140
// or fail on unrecognized properties
146141
try {
147142
r.readValue(aposToQuotes("{'y': 3, 'z':2 }"));
148143
fail("Should fail");
149-
} catch (JsonMappingException e) {
144+
} catch (UnrecognizedPropertyException e) {
150145
verifyException(e, "Unrecognized field");
151146
}
152147

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.*;
44

55
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
67

78
public class ReadOnlyDeserFailOnUnknown2719Test extends BaseMapTest
89
{
@@ -36,7 +37,7 @@ public void testFailOnIgnore() throws Exception
3637
try {
3738
r.readValue(aposToQuotes("{'login':'foo', 'password':'bar'}"));
3839
fail("Should fail");
39-
} catch (JsonMappingException e) {
40+
} catch (MismatchedInputException e) {
4041
verifyException(e, "Ignored field");
4142
}
4243

@@ -45,7 +46,7 @@ public void testFailOnIgnore() throws Exception
4546
try {
4647
r.readValue(aposToQuotes("{'login':'foo', 'username':'bar'}"));
4748
fail("Should fail");
48-
} catch (JsonMappingException e) {
49+
} catch (MismatchedInputException e) {
4950
verifyException(e, "Ignored field");
5051
}
5152
}

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/TestOverloaded.java

+8-40
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,16 @@ static class ArrayListBean extends BaseListBean
3030
public void setList(ArrayList<String> l) { super.setList(l); }
3131
}
3232

33-
// 27-Feb-2010, tatus: Won't fix immediately, need to comment out
34-
/*
35-
static class OverloadBean
36-
{
37-
String a;
38-
39-
public OverloadBean() { }
40-
41-
public void setA(int value) { a = String.valueOf(value); }
42-
public void setA(String value) { a = value; }
43-
}
44-
*/
45-
4633
static class NumberBean {
47-
protected Object value;
48-
49-
public void setValue(Number n) { value = n; }
34+
protected Object value;
35+
36+
public void setValue(Number n) { value = n; }
5037
}
5138

5239
static class WasNumberBean extends NumberBean {
53-
public void setValue(String str) { value = str; }
40+
public void setValue(String str) { value = str; }
5441
}
5542

56-
// [JACKSON-739]
5743
static class Overloaded739
5844
{
5945
protected Object _value;
@@ -69,35 +55,17 @@ static class Overloaded739
6955
* And then a Bean that is conflicting and should not work
7056
*/
7157
static class ConflictBean {
72-
public void setA(ArrayList<Object> a) { }
73-
public void setA(LinkedList<Object> a) { }
58+
public void setA(ArrayList<Object> a) { }
59+
public void setA(LinkedList<Object> a) { }
7460
}
75-
61+
7662
/*
7763
/************************************************************
7864
/* Unit tests, valid
7965
/************************************************************
8066
*/
8167

82-
private final ObjectMapper MAPPER = new ObjectMapper();
83-
84-
/**
85-
* Unit test related to [JACKSON-189]
86-
*/
87-
// 27-Feb-2010, tatus: Won't fix immediately, need to comment out
88-
/*
89-
public void testSimpleOverload() throws Exception
90-
{
91-
OverloadBean bean;
92-
try {
93-
bean = new ObjectMapper().readValue("{ \"a\" : 13 }", OverloadBean.class);
94-
} catch (JsonMappingException e) {
95-
fail("Did not expect an exception, got: "+e.getMessage());
96-
return;
97-
}
98-
assertEquals("13", bean.a);
99-
}
100-
*/
68+
private final ObjectMapper MAPPER = newJsonMapper();
10169

10270
/**
10371
* It should be ok to overload with specialized

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/TestSetterlessProperties.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.annotation.*;
66

77
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
89

910
/**
1011
* Unit tests for verifying that feature requested
@@ -78,10 +79,9 @@ public void testSimpleSetterlessCollectionFailure()
7879
m.readValue
7980
("{\"values\":[ \"abc\", \"def\" ]}", CollectionBean.class);
8081
fail("Expected an exception");
81-
} catch (JsonMappingException e) {
82-
/* Not a good exception, ideally could suggest a need for
83-
* a setter...?
84-
*/
82+
} catch (MismatchedInputException e) {
83+
// Not a good exception, ideally could suggest a need for
84+
// a setter...?
8585
verifyException(e, "Unrecognized field");
8686
}
8787
}
@@ -108,7 +108,7 @@ public void testSimpleSetterlessMapFailure()
108108
m.readValue
109109
("{\"values\":{ \"a\":3 }}", MapBean.class);
110110
fail("Expected an exception");
111-
} catch (JsonMappingException e) {
111+
} catch (MismatchedInputException e) {
112112
verifyException(e, "Unrecognized field");
113113
}
114114
}

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/TestValueAnnotations.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.*;
55

66
import com.fasterxml.jackson.core.*;
7+
78
import com.fasterxml.jackson.databind.*;
89
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
910
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
@@ -285,7 +286,7 @@ public void testOverrideClassInvalid() throws Exception
285286
BrokenCollectionHolder result = MAPPER.readValue
286287
("{ \"strings\" : [ ] }", BrokenCollectionHolder.class);
287288
fail("Expected a failure, but got results: "+result);
288-
} catch (JsonMappingException jme) {
289+
} catch (DatabindException jme) {
289290
verifyException(jme, "not subtype of");
290291
}
291292
}
@@ -355,7 +356,7 @@ public void testOverrideKeyClassInvalid() throws Exception
355356
BrokenMapKeyHolder result = MAPPER.readValue
356357
("{ \"123\" : \"xxx\" }", BrokenMapKeyHolder.class);
357358
fail("Expected a failure, but got results: "+result);
358-
} catch (JsonMappingException jme) {
359+
} catch (DatabindException jme) {
359360
verifyException(jme, "not subtype of");
360361
}
361362
}

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/creators/DisablingCreatorsTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.annotation.JsonProperty;
55

66
import com.fasterxml.jackson.databind.*;
7+
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
78

89
/**
910
* Tests to ensure one can disable {@link JsonCreator} annotations.
@@ -36,7 +37,7 @@ public NonConflictingCreators(String foo, int value) { }
3637

3738
public void testDisabling() throws Exception
3839
{
39-
final ObjectMapper mapper = objectMapper();
40+
final ObjectMapper mapper = newJsonMapper();
4041

4142
// first, non-problematic case
4243
NonConflictingCreators value = mapper.readValue(quote("abc"), NonConflictingCreators.class);
@@ -47,7 +48,7 @@ public void testDisabling() throws Exception
4748
try {
4849
/*ConflictingCreators value =*/ mapper.readValue(quote("abc"), ConflictingCreators.class);
4950
fail("Should have failed with JsonCreator conflict");
50-
} catch (JsonMappingException e) {
51+
} catch (InvalidDefinitionException e) {
5152
verifyException(e, "Conflicting property-based creators");
5253
}
5354
}

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/creators/FailOnNullCreatorTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
67

78
/**
89
* Tests to ensure that deserialization fails when a bean property has a null value
@@ -43,15 +44,15 @@ public void testRequiredNonNullParam() throws Exception
4344
try {
4445
r.readValue(aposToQuotes("{}"));
4546
fail("Should not pass third test");
46-
} catch (JsonMappingException e) {
47+
} catch (MismatchedInputException e) {
4748
verifyException(e, "Null value for creator property 'name'");
4849
}
4950

5051
// Fourth: throws exception if property is set to null explicitly
5152
try {
5253
r.readValue(aposToQuotes("{'age': 5, 'name': null}"));
5354
fail("Should not pass fourth test");
54-
} catch (JsonMappingException e) {
55+
} catch (MismatchedInputException e) {
5556
verifyException(e, "Null value for creator property 'name'");
5657
}
5758
}

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/creators/RequiredCreatorTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.*;
44

55
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
67

78
public class RequiredCreatorTest extends BaseMapTest
89
{
@@ -78,7 +79,7 @@ public void testRequiredAnnotatedParam() throws Exception
7879
try {
7980
POINT_READER.readValue(aposToQuotes("{'y':3}"));
8081
fail("Should not pass");
81-
} catch (JsonMappingException e) {
82+
} catch (MismatchedInputException e) {
8283
verifyException(e, "Missing required creator property 'x' (index 0)");
8384
}
8485
}
@@ -97,7 +98,7 @@ public void testRequiredGloballyParam() throws Exception
9798
try {
9899
r.readValue(aposToQuotes("{'x':6}"));
99100
fail("Should not pass");
100-
} catch (JsonMappingException e) {
101+
} catch (MismatchedInputException e) {
101102
verifyException(e, "Missing creator property 'y' (index 1)");
102103
}
103104
}
@@ -109,7 +110,7 @@ public void testRequiredViaParameter2591() throws Exception
109110
try {
110111
/*LoginUserResponse resp =*/ MAPPER.readValue(input, LoginUserResponse.class);
111112
fail("Shoud not pass");
112-
} catch (JsonMappingException e) {
113+
} catch (MismatchedInputException e) {
113114
verifyException(e, "Missing required creator property 'otp'");
114115
}
115116
}

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorNullPrimitives.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import com.fasterxml.jackson.databind.BaseMapTest;
77
import com.fasterxml.jackson.databind.DeserializationFeature;
8-
import com.fasterxml.jackson.databind.JsonMappingException;
98
import com.fasterxml.jackson.databind.ObjectMapper;
109
import com.fasterxml.jackson.databind.ObjectReader;
10+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
1111

1212
import java.io.IOException;
1313

14-
public class TestCreatorNullPrimitives extends BaseMapTest {
15-
14+
public class TestCreatorNullPrimitives extends BaseMapTest
15+
{
1616
// [databind#2101]
1717
static class JsonEntity {
1818
protected final int x;
@@ -50,7 +50,7 @@ public void testCreatorNullPrimitive() throws IOException {
5050
try {
5151
r.readValue(json);
5252
fail("Should not have succeeded");
53-
} catch (JsonMappingException e) {
53+
} catch (MismatchedInputException e) {
5454
verifyException(e, "Cannot map `null` into type `int`");
5555
assertEquals(1, e.getPath().size());
5656
assertEquals("y", e.getPath().get(0).getFieldName());
@@ -64,7 +64,7 @@ public void testCreatorNullPrimitiveInNestedObject() throws IOException {
6464
try {
6565
r.readValue(json);
6666
fail("Should not have succeeded");
67-
} catch (JsonMappingException e) {
67+
} catch (MismatchedInputException e) {
6868
verifyException(e, "Cannot map `null` into type `int`");
6969
assertEquals(2, e.getPath().size());
7070
assertEquals("y", e.getPath().get(1).getFieldName());

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void testJackson438() throws Exception
242242
try {
243243
MAPPER.readValue("{ \"name\":\"foobar\" }", BeanFor438.class);
244244
fail("Should have failed");
245-
} catch (JsonMappingException e0) {
245+
} catch (Exception e0) {
246246
e = e0;
247247
}
248248
if (!(e instanceof ValueInstantiationException)) {

Diff for: src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorsDelegating.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.fasterxml.jackson.annotation.JacksonInject;
66
import com.fasterxml.jackson.annotation.JsonCreator;
77
import com.fasterxml.jackson.annotation.JsonProperty;
8-
8+
import com.fasterxml.jackson.core.JacksonException;
99
import com.fasterxml.jackson.core.JsonParser;
1010
import com.fasterxml.jackson.core.JsonToken;
1111

@@ -180,7 +180,7 @@ public void testWithCtorAndDelegate() throws Exception
180180
CtorBean711 bean = null;
181181
try {
182182
bean = mapper.readValue("38", CtorBean711.class);
183-
} catch (JsonMappingException e) {
183+
} catch (JacksonException e) {
184184
fail("Did not expect problems, got: "+e.getMessage());
185185
}
186186
assertEquals(38, bean.age);
@@ -196,7 +196,7 @@ public void testWithFactoryAndDelegate() throws Exception
196196
FactoryBean711 bean = null;
197197
try {
198198
bean = mapper.readValue("38", FactoryBean711.class);
199-
} catch (JsonMappingException e) {
199+
} catch (JacksonException e) {
200200
fail("Did not expect problems, got: "+e.getMessage());
201201
}
202202
assertEquals(38, bean.age);

0 commit comments

Comments
 (0)