3
3
import java .util .List ;
4
4
import java .util .Map ;
5
5
6
- import com .fasterxml .jackson .annotation .JsonSetter ;
7
- import com .fasterxml .jackson .annotation .Nulls ;
8
6
import com .fasterxml .jackson .core .type .TypeReference ;
9
7
10
- import com .fasterxml .jackson .databind .*;
11
8
import com .fasterxml .jackson .dataformat .xml .XmlMapper ;
12
9
import com .fasterxml .jackson .dataformat .xml .XmlTestBase ;
13
10
14
- // Copied from `com.fasterxml.jackson.databind.deser.filter.` in `jackson-databind`
15
- public class NullConversionsGenericTest extends XmlTestBase
11
+ // Note: copied from coercion tests of `jackson-databind`
12
+ public class CoerceFromEmptyStringTest extends XmlTestBase
16
13
{
17
14
static class PointWrapper {
18
- @ JsonSetter (nulls =Nulls .AS_EMPTY )
19
15
public Point p ;
20
16
}
21
17
22
18
static class GeneralEmpty <T > {
23
- // 09-Feb-2017, tatu: Should only need annotation either for field OR setter, not both:
24
- // @JsonSetter(nulls=Nulls.AS_EMPTY)
25
19
T value ;
26
20
27
21
protected GeneralEmpty () { }
28
22
public GeneralEmpty (T v ) { value = v ; }
29
23
30
- @ JsonSetter (nulls =Nulls .AS_EMPTY )
31
24
public void setValue (T v ) {
32
25
value = v ;
33
26
}
@@ -36,7 +29,6 @@ public void setValue(T v) {
36
29
}
37
30
38
31
static class NoCtorWrapper {
39
- @ JsonSetter (nulls =Nulls .AS_EMPTY )
40
32
public NoCtorPOJO value ;
41
33
}
42
34
@@ -73,19 +65,8 @@ public void testNullsToGenericPojo() throws Exception
73
65
Point p = result .value ;
74
66
assertEquals (0 , p .x );
75
67
assertEquals (0 , p .y );
76
-
77
- // and then also failing case with no suitable creator:
78
- try {
79
- /* NoCtorWrapper nogo =*/ MAPPER .readValue (EMPTY_XML ,
80
- NoCtorWrapper .class );
81
- fail ("Should not pass" );
82
- } catch (JsonMappingException e ) {
83
- verifyException (e , "Cannot create empty instance" );
84
- }
85
68
}
86
69
87
- // 04-May-2018, tatu: In theory could be supportable, but wrapping (or not)
88
- // of Collections, other requirements, make it... not that easy.
89
70
public void testNullsToEmptyCollection () throws Exception
90
71
{
91
72
GeneralEmpty <List <String >> result = MAPPER .readValue (EMPTY_XML ,
@@ -100,7 +81,6 @@ public void testNullsToEmptyCollection() throws Exception
100
81
assertEquals (0 , result2 .value .size ());
101
82
}
102
83
103
- // 04-May-2018, tatu: Maps and XML do not mix well, alas:
104
84
public void testNullsToEmptyMap () throws Exception
105
85
{
106
86
GeneralEmpty <Map <String ,String >> result = MAPPER .readValue (EMPTY_XML ,
@@ -127,7 +107,6 @@ public void testNullsToEmptyArrays() throws Exception
127
107
new TypeReference <GeneralEmpty <int []>>() { });
128
108
assertNotNull (result3 .value );
129
109
assertEquals (0 , result3 .value .length );
130
-
131
110
GeneralEmpty <double []> result4 = MAPPER .readValue (doc ,
132
111
new TypeReference <GeneralEmpty <double []>>() { });
133
112
assertNotNull (result4 .value );
0 commit comments