@@ -56,7 +56,7 @@ static class MyNoArgException extends Exception
56
56
57
57
private final ObjectMapper MAPPER = new ObjectMapper ();
58
58
59
- public void testIOException () throws IOException
59
+ public void testIOException () throws Exception
60
60
{
61
61
IOException ioe = new IOException ("TEST" );
62
62
String json = MAPPER .writerWithDefaultPrettyPrinter ()
@@ -65,7 +65,7 @@ public void testIOException() throws IOException
65
65
assertEquals (ioe .getMessage (), result .getMessage ());
66
66
}
67
67
68
- public void testWithCreator () throws IOException
68
+ public void testWithCreator () throws Exception
69
69
{
70
70
final String MSG = "the message" ;
71
71
String json = MAPPER .writeValueAsString (new MyException (MSG , 3 ));
@@ -82,7 +82,7 @@ public void testWithCreator() throws IOException
82
82
assertTrue (result .stuff .containsKey ("suppressed" ));
83
83
}
84
84
85
- public void testWithNullMessage () throws IOException
85
+ public void testWithNullMessage () throws Exception
86
86
{
87
87
final ObjectMapper mapper = new ObjectMapper ();
88
88
mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
@@ -92,14 +92,14 @@ public void testWithNullMessage() throws IOException
92
92
assertNull (result .getMessage ());
93
93
}
94
94
95
- public void testNoArgsException () throws IOException
95
+ public void testNoArgsException () throws Exception
96
96
{
97
97
MyNoArgException exc = MAPPER .readValue ("{}" , MyNoArgException .class );
98
98
assertNotNull (exc );
99
99
}
100
100
101
101
// try simulating JDK 7 behavior
102
- public void testJDK7SuppressionProperty () throws IOException
102
+ public void testJDK7SuppressionProperty () throws Exception
103
103
{
104
104
Exception exc = MAPPER .readValue ("{\" suppressed\" :[]}" , IOException .class );
105
105
assertNotNull (exc );
@@ -124,7 +124,7 @@ public void testSingleValueArrayDeserialization() throws Exception
124
124
_assertEquality (exp .getStackTrace (), cloned .getStackTrace ());
125
125
}
126
126
127
- public void testExceptionCauseDeserialization () throws IOException
127
+ public void testExceptionCauseDeserialization () throws Exception
128
128
{
129
129
ObjectMapper mapper = new ObjectMapper ();
130
130
@@ -139,7 +139,7 @@ public void testExceptionCauseDeserialization() throws IOException
139
139
}
140
140
141
141
142
- public void testSuppressedGenericThrowableDeserialization () throws IOException
142
+ public void testSuppressedGenericThrowableDeserialization () throws Exception
143
143
{
144
144
ObjectMapper mapper = new ObjectMapper ();
145
145
@@ -155,7 +155,7 @@ public void testSuppressedGenericThrowableDeserialization() throws IOException
155
155
_assertEquality (exp .getSuppressed ()[0 ].getStackTrace (), act .getSuppressed ()[0 ].getStackTrace ());
156
156
}
157
157
158
- public void testSuppressedTypedExceptionDeserialization () throws IOException
158
+ public void testSuppressedTypedExceptionDeserialization () throws Exception
159
159
{
160
160
PolymorphicTypeValidator typeValidator = BasicPolymorphicTypeValidator .builder ()
161
161
.allowIfSubTypeIsArray ()
@@ -231,7 +231,7 @@ public void testSingleValueArrayDeserializationException() throws Exception {
231
231
}
232
232
233
233
// mostly to help with XML module (and perhaps CSV)
234
- public void testLineNumberAsString () throws IOException
234
+ public void testLineNumberAsString () throws Exception
235
235
{
236
236
Exception exc = MAPPER .readValue (a2q (
237
237
"{'message':'Test',\n 'stackTrace': "
@@ -241,7 +241,7 @@ public void testLineNumberAsString() throws IOException
241
241
}
242
242
243
243
// [databind#1842]
244
- public void testNullAsMessage () throws IOException
244
+ public void testNullAsMessage () throws Exception
245
245
{
246
246
Exception exc = MAPPER .readValue (a2q (
247
247
"{'message':null, 'localizedMessage':null }"
@@ -278,4 +278,24 @@ private void _testRoundtripWith(ObjectMapper mapper) throws Exception
278
278
assertNotNull (result .getCause ());
279
279
assertEquals (root .getMessage (), result .getCause ().getMessage ());
280
280
}
281
+
282
+ // [databind#4248]
283
+ public void testWithDups () throws Exception
284
+ {
285
+ // NOTE: by default JSON parser does NOT fail on duplicate properties;
286
+ // we only use them to mimic formats like XML where duplicates can occur
287
+ // (or, malicious JSON...)
288
+ final StringBuilder sb = new StringBuilder (100 );
289
+ sb .append ("{" );
290
+ sb .append ("'suppressed': [],\n " );
291
+ sb .append ("'cause': null,\n " );
292
+ for (int i = 0 ; i < 10 ; ++i ) { // just needs to be more than max distinct props
293
+ sb .append ("'stackTrace': [],\n " );
294
+ }
295
+ sb .append ("'message': 'foo',\n " );
296
+ sb .append ("'localizedMessage': 'bar'\n }" );
297
+ IOException exc = MAPPER .readValue (a2q (sb .toString ()), IOException .class );
298
+ assertNotNull (exc );
299
+ assertEquals ("foo" , exc .getLocalizedMessage ());
300
+ }
281
301
}
0 commit comments