1
1
package com .fasterxml .jackson .databind .ser .dos ;
2
2
3
- import com .fasterxml .jackson .core .StreamWriteConstraints ;
4
- import com .fasterxml .jackson .databind .BaseMapTest ;
5
- import com .fasterxml .jackson .databind .JsonMappingException ;
6
- import com .fasterxml .jackson .databind .ObjectMapper ;
7
- import com .fasterxml .jackson .databind .exc .InvalidDefinitionException ;
8
- import com .fasterxml .jackson .databind .ser .CyclicTypeSerTest ;
9
-
10
3
import java .util .ArrayList ;
11
4
import java .util .List ;
12
5
6
+ import com .fasterxml .jackson .core .StreamWriteConstraints ;
7
+
8
+ import com .fasterxml .jackson .databind .*;
9
+ import com .fasterxml .jackson .databind .exc .InvalidDefinitionException ;
10
+
13
11
/**
14
12
* Simple unit tests to verify that we fail gracefully if you attempt to serialize
15
13
* data that is cyclic (eg a list that contains itself).
16
14
*/
17
15
public class CyclicDataSerTest
18
16
extends BaseMapTest
19
17
{
18
+ static class CyclicBean
19
+ {
20
+ CyclicBean _next ;
21
+ final String _name ;
22
+
23
+ public CyclicBean (CyclicBean next , String name ) {
24
+ _next = next ;
25
+ _name = name ;
26
+ }
27
+
28
+ public CyclicBean getNext () { return _next ; }
29
+ public String getName () { return _name ; }
30
+
31
+ public void assignNext (CyclicBean n ) { _next = n ; }
32
+ }
33
+
20
34
private final ObjectMapper MAPPER = newJsonMapper ();
21
35
22
36
public void testLinkedAndCyclic () throws Exception {
23
- CyclicTypeSerTest . Bean bean = new CyclicTypeSerTest . Bean (null , "last" );
37
+ CyclicBean bean = new CyclicBean (null , "last" );
24
38
bean .assignNext (bean );
25
39
try {
26
40
writeAndMap (MAPPER , bean );
@@ -36,12 +50,12 @@ public void testListWithSelfReference() throws Exception {
36
50
list .add (list );
37
51
try {
38
52
writeAndMap (MAPPER , list );
39
- fail ("expected JsonMappingException " );
40
- } catch (JsonMappingException jmex ) {
53
+ fail ("expected DatabindException " );
54
+ } catch (DatabindException e ) {
41
55
String exceptionPrefix = String .format ("Document nesting depth (%d) exceeds the maximum allowed" ,
42
56
StreamWriteConstraints .DEFAULT_MAX_DEPTH + 1 );
43
- assertTrue ("JsonMappingException message is as expected?" ,
44
- jmex .getMessage ().startsWith (exceptionPrefix ));
57
+ assertTrue ("DatabindException message is as expected?" ,
58
+ e .getMessage ().startsWith (exceptionPrefix ));
45
59
}
46
60
}
47
61
}
0 commit comments