@@ -51,6 +51,8 @@ public static void addAll(Map<String, JsonSerializer<?>> allDeserializers)
51
51
protected abstract static class Base <T > extends StdScalarSerializer <T >
52
52
implements ContextualSerializer
53
53
{
54
+ protected final static Integer EMPTY_INTEGER = Integer .valueOf (0 );
55
+
54
56
protected final JsonParser .NumberType _numberType ;
55
57
protected final String _schemaType ;
56
58
protected final boolean _isInt ;
@@ -116,16 +118,22 @@ public JsonSerializer<?> createContextual(SerializerProvider prov,
116
118
@ JacksonStdImpl
117
119
public final static class ShortSerializer extends Base <Short >
118
120
{
121
+ private final static Short EMPTY = (short ) 0 ;
119
122
final static ShortSerializer instance = new ShortSerializer ();
120
-
123
+
121
124
public ShortSerializer () { super (Short .class , JsonParser .NumberType .INT , "number" ); }
122
125
126
+ @ Override
127
+ public boolean isEmpty (SerializerProvider prov , Short value ) {
128
+ return EMPTY .equals (value );
129
+ }
130
+
123
131
@ Override
124
132
public void serialize (Short value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
125
133
gen .writeNumber (value .shortValue ());
126
134
}
127
135
}
128
-
136
+
129
137
/**
130
138
* This is the special serializer for regular {@link java.lang.Integer}s
131
139
* (and primitive ints)
@@ -153,6 +161,11 @@ public void serializeWithType(Object value, JsonGenerator gen,
153
161
// no type info, just regular serialization
154
162
serialize (value , gen , provider );
155
163
}
164
+
165
+ @ Override
166
+ public boolean isEmpty (SerializerProvider prov , Object value ) {
167
+ return EMPTY_INTEGER .equals (value );
168
+ }
156
169
}
157
170
158
171
/**
@@ -164,11 +177,16 @@ public void serializeWithType(Object value, JsonGenerator gen,
164
177
public final static class IntLikeSerializer extends Base <Number >
165
178
{
166
179
final static IntLikeSerializer instance = new IntLikeSerializer ();
167
-
180
+
168
181
public IntLikeSerializer () {
169
182
super (Number .class , JsonParser .NumberType .INT , "integer" );
170
183
}
171
-
184
+
185
+ @ Override
186
+ public boolean isEmpty (SerializerProvider prov , Number value ) {
187
+ return value .intValue () == 0 ;
188
+ }
189
+
172
190
@ Override
173
191
public void serialize (Number value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
174
192
gen .writeNumber (value .intValue ());
@@ -178,26 +196,40 @@ public void serialize(Number value, JsonGenerator gen, SerializerProvider provid
178
196
@ JacksonStdImpl
179
197
public final static class LongSerializer extends Base <Object >
180
198
{
199
+ private final static Long EMPTY = 0L ;
200
+
181
201
final static LongSerializer instance = new LongSerializer ();
182
202
183
203
public LongSerializer () { super (Long .class , JsonParser .NumberType .LONG , "number" ); }
184
-
204
+
205
+ @ Override
206
+ public boolean isEmpty (SerializerProvider prov , Object value ) {
207
+ return EMPTY .equals (value );
208
+ }
209
+
185
210
@ Override
186
211
public void serialize (Object value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
187
212
gen .writeNumber (((Long ) value ).longValue ());
188
213
}
189
214
}
190
-
215
+
191
216
@ JacksonStdImpl
192
- public final static class FloatSerializer extends Base <Float >
217
+ public final static class FloatSerializer extends Base <Object >
193
218
{
219
+ private final static Float EMPTY = 0f ;
220
+
194
221
final static FloatSerializer instance = new FloatSerializer ();
195
-
222
+
196
223
public FloatSerializer () { super (Float .class , JsonParser .NumberType .FLOAT , "number" ); }
197
-
224
+
198
225
@ Override
199
- public void serialize (Float value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
200
- gen .writeNumber (value .floatValue ());
226
+ public boolean isEmpty (SerializerProvider prov , Object value ) {
227
+ return EMPTY .equals (value );
228
+ }
229
+
230
+ @ Override
231
+ public void serialize (Object value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
232
+ gen .writeNumber (((Float ) value ).floatValue ());
201
233
}
202
234
}
203
235
@@ -211,10 +243,17 @@ public void serialize(Float value, JsonGenerator gen, SerializerProvider provide
211
243
@ JacksonStdImpl
212
244
public final static class DoubleSerializer extends Base <Object >
213
245
{
246
+ private final static Double EMPTY = 0d ;
247
+
214
248
final static DoubleSerializer instance = new DoubleSerializer ();
215
249
216
250
public DoubleSerializer () { super (Double .class , JsonParser .NumberType .DOUBLE , "number" ); }
217
-
251
+
252
+ @ Override
253
+ public boolean isEmpty (SerializerProvider prov , Object value ) {
254
+ return EMPTY .equals (value );
255
+ }
256
+
218
257
@ Override
219
258
public void serialize (Object value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
220
259
gen .writeNumber (((Double ) value ).doubleValue ());
0 commit comments