7
7
import com .fasterxml .jackson .core .JsonGenerator ;
8
8
import com .fasterxml .jackson .databind .*;
9
9
import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
10
+ import com .fasterxml .jackson .databind .ser .std .StdScalarSerializer ;
10
11
import com .fasterxml .jackson .databind .ser .std .StdSerializer ;
11
12
12
- public class TestAnyGetter extends BaseMapTest
13
+ public class AnyGetterTest extends BaseMapTest
13
14
{
14
15
static class Bean
15
16
{
@@ -84,6 +85,40 @@ public void serialize(Object value, JsonGenerator jgen,
84
85
}
85
86
}
86
87
88
+ // [databind#1124]
89
+ static class Bean1124
90
+ {
91
+ protected Map <String ,String > additionalProperties ;
92
+
93
+ public void addAdditionalProperty (String key , String value ) {
94
+ if (additionalProperties == null ) {
95
+ additionalProperties = new HashMap <String ,String >();
96
+ }
97
+ additionalProperties .put (key ,value );
98
+ }
99
+
100
+ public void setAdditionalProperties (Map <String , String > additionalProperties ) {
101
+ this .additionalProperties = additionalProperties ;
102
+ }
103
+
104
+ @ JsonAnyGetter
105
+ @ JsonSerialize (contentUsing =MyUCSerializer .class )
106
+ public Map <String ,String > getAdditionalProperties () { return additionalProperties ; }
107
+ }
108
+
109
+ // [databind#1124]
110
+ @ SuppressWarnings ("serial" )
111
+ static class MyUCSerializer extends StdScalarSerializer <String >
112
+ {
113
+ public MyUCSerializer () { super (String .class ); }
114
+
115
+ @ Override
116
+ public void serialize (String value , JsonGenerator gen ,
117
+ SerializerProvider provider ) throws IOException {
118
+ gen .writeString (value .toUpperCase ());
119
+ }
120
+ }
121
+
87
122
/*
88
123
/**********************************************************
89
124
/* Test cases
@@ -101,7 +136,6 @@ public void testSimpleJsonValue() throws Exception
101
136
assertEquals (Boolean .TRUE , map .get ("a" ));
102
137
}
103
138
104
- // [JACKSON-392]
105
139
public void testAnyOnly () throws Exception
106
140
{
107
141
ObjectMapper m ;
@@ -134,4 +168,14 @@ public void testIssue705() throws Exception
134
168
String json = MAPPER .writeValueAsString (input );
135
169
assertEquals ("{\" stuff\" :\" [key/value]\" }" , json );
136
170
}
171
+
172
+ // [databind#1124]
173
+ public void testAnyGetterWithValueSerializer () throws Exception
174
+ {
175
+ ObjectMapper mapper = new ObjectMapper ();
176
+ Bean1124 input = new Bean1124 ();
177
+ input .addAdditionalProperty ("key" , "value" );
178
+ String json = mapper .writeValueAsString (input );
179
+ assertEquals ("{\" key\" :\" VALUE\" }" , json );
180
+ }
137
181
}
0 commit comments