@@ -108,7 +108,7 @@ public JsonDocumentWriter objectKey(String key) {
108
108
throw new IllegalArgumentException ( "key cannot be null or empty" );
109
109
}
110
110
111
- if (this .processingStates .getCurrent (). equals ( JsonProcessingState . OBJECT )) {
111
+ if (JsonProcessingState . OBJECT . equals ( this .processingStates .getCurrent ())) {
112
112
// we have started an object, and we are adding an item key: we do add a separator.
113
113
this .appender .append ( StringJsonDocumentMarker .SEPARATOR .getMarkerCharacter () );
114
114
}
@@ -222,13 +222,24 @@ public JsonDocumentWriter stringValue(String value) {
222
222
}
223
223
224
224
@ Override
225
- public JsonDocumentWriter serializeJsonValue (Object value , JavaType <Object > javaType , JdbcType jdbcType , WrapperOptions options ) {
225
+ public < T > JsonDocumentWriter serializeJsonValue (Object value , JavaType <T > javaType , JdbcType jdbcType , WrapperOptions options ) {
226
226
addItemsSeparator ();
227
227
convertedBasicValueToString (value , options ,this .appender ,javaType ,jdbcType );
228
228
moveProcessingStateMachine ();
229
229
return this ;
230
230
}
231
231
232
+ private <T > void convertedCastBasicValueToString (Object value ,
233
+ WrapperOptions options ,
234
+ JsonAppender appender ,
235
+ JavaType <T > javaType ,
236
+ JdbcType jdbcType ) {
237
+ assert javaType .isInstance ( value );
238
+ //noinspection unchecked
239
+ convertedBasicValueToString ( (T ) value , options , appender , javaType , jdbcType );
240
+ }
241
+
242
+
232
243
/**
233
244
* Converts a value to String according to its mapping type.
234
245
* This method serializes the value and writes it into the underlying appender
@@ -238,12 +249,15 @@ public JsonDocumentWriter serializeJsonValue(Object value, JavaType<Object> java
238
249
* @param jdbcType the JDBC SQL type of the value
239
250
* @param options the wapping options.
240
251
*/
241
- private void convertedBasicValueToString (
252
+ private < T > void convertedBasicValueToString (
242
253
Object value ,
243
254
WrapperOptions options ,
244
255
JsonAppender appender ,
245
- JavaType <Object > javaType ,
256
+ JavaType <T > javaType ,
246
257
JdbcType jdbcType ) {
258
+
259
+ assert javaType .isInstance ( value );
260
+
247
261
switch ( jdbcType .getDefaultSqlTypeCode () ) {
248
262
case SqlTypes .TINYINT :
249
263
case SqlTypes .SMALLINT :
@@ -264,7 +278,7 @@ private void convertedBasicValueToString(
264
278
case SqlTypes .REAL :
265
279
case SqlTypes .DOUBLE :
266
280
// These types fit into the native representation of JSON, so let's use that
267
- javaType .appendEncodedString ( appender , value );
281
+ javaType .appendEncodedString ( appender , ( T ) value );
268
282
break ;
269
283
case SqlTypes .CHAR :
270
284
case SqlTypes .NCHAR :
@@ -290,15 +304,15 @@ private void convertedBasicValueToString(
290
304
// These literals can contain the '"' character, so we need to escape it
291
305
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
292
306
appender .startEscaping ();
293
- javaType .appendEncodedString ( appender , value );
307
+ javaType .appendEncodedString ( appender , ( T ) value );
294
308
appender .endEscaping ();
295
309
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
296
310
break ;
297
311
case SqlTypes .DATE :
298
312
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
299
313
JdbcDateJavaType .INSTANCE .appendEncodedString (
300
314
appender ,
301
- javaType .unwrap ( value , java .sql .Date .class , options )
315
+ javaType .unwrap ( ( T ) value , java .sql .Date .class , options )
302
316
);
303
317
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
304
318
break ;
@@ -308,23 +322,23 @@ private void convertedBasicValueToString(
308
322
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
309
323
JdbcTimeJavaType .INSTANCE .appendEncodedString (
310
324
appender ,
311
- javaType .unwrap ( value , java .sql .Time .class , options )
325
+ javaType .unwrap ( ( T ) value , java .sql .Time .class , options )
312
326
);
313
327
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
314
328
break ;
315
329
case SqlTypes .TIMESTAMP :
316
330
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
317
331
JdbcTimestampJavaType .INSTANCE .appendEncodedString (
318
332
appender ,
319
- javaType .unwrap ( value , java .sql .Timestamp .class , options )
333
+ javaType .unwrap ( ( T ) value , java .sql .Timestamp .class , options )
320
334
);
321
335
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
322
336
break ;
323
337
case SqlTypes .TIMESTAMP_WITH_TIMEZONE :
324
338
case SqlTypes .TIMESTAMP_UTC :
325
339
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
326
340
DateTimeFormatter .ISO_OFFSET_DATE_TIME .formatTo (
327
- javaType .unwrap ( value , OffsetDateTime .class , options ),
341
+ javaType .unwrap ( ( T ) value , OffsetDateTime .class , options ),
328
342
appender
329
343
);
330
344
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
@@ -335,7 +349,7 @@ private void convertedBasicValueToString(
335
349
case SqlTypes .UUID :
336
350
// These types need to be serialized as JSON string, but don't have a need for escaping
337
351
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
338
- javaType .appendEncodedString ( appender , value );
352
+ javaType .appendEncodedString ( appender , ( T ) value );
339
353
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
340
354
break ;
341
355
case SqlTypes .BINARY :
@@ -346,7 +360,7 @@ private void convertedBasicValueToString(
346
360
case SqlTypes .MATERIALIZED_BLOB :
347
361
// These types need to be serialized as JSON string, and for efficiency uses appendString directly
348
362
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
349
- appender .write ( javaType .unwrap ( value , byte [].class , options ) );
363
+ appender .write ( javaType .unwrap ( ( T ) value , byte [].class , options ) );
350
364
appender .append ( StringJsonDocumentMarker .QUOTE .getMarkerCharacter () );
351
365
break ;
352
366
case SqlTypes .ARRAY :
0 commit comments