@@ -38,16 +38,24 @@ public BooleanWrapper() { }
38
38
public BooleanWrapper (Boolean value ) { b = value ; }
39
39
}
40
40
41
+ // [databind#3080]
42
+ protected static class PrimitiveBooleanWrapper {
43
+ public boolean b ;
44
+
45
+ public PrimitiveBooleanWrapper () { }
46
+ public PrimitiveBooleanWrapper (boolean value ) { b = value ; }
47
+ }
48
+
41
49
static class AltBoolean extends BooleanWrapper
42
50
{
43
51
public AltBoolean () { }
44
52
public AltBoolean (Boolean b ) { super (b ); }
45
53
}
46
54
47
55
/*
48
- /**********************************************************
56
+ /**********************************************************************
49
57
/* Test methods
50
- /**********************************************************
58
+ /**********************************************************************
51
59
*/
52
60
53
61
private final static ObjectMapper MAPPER = newJsonMapper ();
@@ -56,11 +64,39 @@ public void testShapeViaDefaults() throws Exception
56
64
{
57
65
assertEquals (aposToQuotes ("{'b':true}" ),
58
66
MAPPER .writeValueAsString (new BooleanWrapper (true )));
59
- ObjectMapper m = newJsonMapper ();
60
- m .configOverride (Boolean .class )
61
- .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .NUMBER ));
67
+ ObjectMapper m = jsonMapperBuilder ()
68
+ .withConfigOverride (Boolean .class ,
69
+ cfg -> cfg .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .NUMBER )
70
+ )).build ();
62
71
assertEquals (aposToQuotes ("{'b':1}" ),
63
72
m .writeValueAsString (new BooleanWrapper (true )));
73
+
74
+ m = jsonMapperBuilder ()
75
+ .withConfigOverride (Boolean .class ,
76
+ cfg -> cfg .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .STRING )
77
+ )).build ();
78
+ assertEquals (aposToQuotes ("{'b':'true'}" ),
79
+ m .writeValueAsString (new BooleanWrapper (true )));
80
+ }
81
+
82
+ // [databind#3080]
83
+ public void testPrimitiveShapeViaDefaults () throws Exception
84
+ {
85
+ assertEquals (aposToQuotes ("{'b':true}" ),
86
+ MAPPER .writeValueAsString (new PrimitiveBooleanWrapper (true )));
87
+ ObjectMapper m = jsonMapperBuilder ()
88
+ .withConfigOverride (Boolean .TYPE , cfg ->
89
+ cfg .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .NUMBER ))
90
+ ).build ();
91
+ assertEquals (aposToQuotes ("{'b':1}" ),
92
+ m .writeValueAsString (new PrimitiveBooleanWrapper (true )));
93
+
94
+ m = jsonMapperBuilder ()
95
+ .withConfigOverride (Boolean .TYPE , cfg ->
96
+ cfg .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .STRING ))
97
+ ).build ();
98
+ assertEquals (aposToQuotes ("{'b':'true'}" ),
99
+ m .writeValueAsString (new PrimitiveBooleanWrapper (true )));
64
100
}
65
101
66
102
public void testShapeOnProperty () throws Exception
0 commit comments