40
40
import java .util .concurrent .atomic .AtomicReference ;
41
41
import java .util .function .Consumer ;
42
42
43
+ import com .fasterxml .jackson .core .JsonGenerator ;
44
+ import com .fasterxml .jackson .databind .SerializerProvider ;
45
+ import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
46
+ import com .fasterxml .jackson .databind .ser .std .StdSerializer ;
43
47
import org .junit .jupiter .api .Test ;
44
48
import org .mockito .Mockito ;
45
49
@@ -420,7 +424,7 @@ void deserializesJavaTimeFrimBytes() {
420
424
}
421
425
422
426
@ Test // GH-2601
423
- public void internalObjectMapperCustomization () {
427
+ void internalObjectMapperCustomization () {
424
428
425
429
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer ();
426
430
@@ -432,20 +436,63 @@ public void internalObjectMapperCustomization() {
432
436
433
437
assertThat (serializer .configure (configurer )).isSameAs (serializer );
434
438
435
- verify (mockObjectMapper , times (1 )).registerModule (eq ( mockModule ) );
439
+ verify (mockObjectMapper , times (1 )).registerModule (mockModule );
436
440
verifyNoMoreInteractions (mockObjectMapper );
437
441
verifyNoInteractions (mockModule );
438
442
}
439
443
440
444
@ Test // GH-2601
441
- public void configureWithNullConsumerThrowsIllegalArgumentException () {
445
+ void configureWithNullConsumerThrowsIllegalArgumentException () {
442
446
443
447
assertThatIllegalArgumentException ()
444
448
.isThrownBy (() -> new GenericJackson2JsonRedisSerializer ().configure (null ))
445
449
.withMessage ("Consumer used to configure and customize ObjectMapper must not be null" )
446
450
.withNoCause ();
447
451
}
448
452
453
+ @ Test
454
+ void defaultSerializeAndDeserializeNullValueWithBuilderClass () {
455
+ GenericJackson2JsonRedisSerializer serializer = GenericJackson2JsonRedisSerializer .builder (
456
+ new ObjectMapper ().enableDefaultTyping (DefaultTyping .EVERYTHING , As .PROPERTY ),
457
+ JacksonObjectReader .create (), JacksonObjectWriter .create ())
458
+ .classPropertyTypeName (null )
459
+ .registerNullValueSerializer (null )
460
+ .build ();
461
+
462
+ serializeAndDeserializeNullValue (serializer );
463
+ }
464
+
465
+ @ Test
466
+ void customSerializeAndDeserializeNullValueWithBuilderClass () {
467
+ GenericJackson2JsonRedisSerializer serializer = GenericJackson2JsonRedisSerializer .builder (
468
+ new ObjectMapper (), JacksonObjectReader .create (), JacksonObjectWriter .create ())
469
+ .classPropertyTypeName (null )
470
+ .registerNullValueSerializer (new StdSerializer <>(NullValue .class ) {
471
+ @ Override
472
+ public void serialize (NullValue nullValue ,
473
+ JsonGenerator jsonGenerator ,
474
+ SerializerProvider serializerProvider ) throws IOException {
475
+ jsonGenerator .writeNull ();
476
+ }
477
+
478
+ @ Override
479
+ public void serializeWithType (NullValue value , JsonGenerator jsonGenerator , SerializerProvider serializers ,
480
+ TypeSerializer typeSerializer ) throws IOException {
481
+
482
+ serialize (value , jsonGenerator , serializers );
483
+ }
484
+ })
485
+ .build ();
486
+
487
+ NullValue nv = BeanUtils .instantiateClass (NullValue .class );
488
+
489
+ byte [] serializedValue = serializer .serialize (nv );
490
+ assertThat (serializedValue ).isNotNull ();
491
+
492
+ Object deserializedValue = serializer .deserialize (serializedValue );
493
+ assertThat (deserializedValue ).isNull ();
494
+ }
495
+
449
496
private static void serializeAndDeserializeNullValue (GenericJackson2JsonRedisSerializer serializer ) {
450
497
451
498
NullValue nv = BeanUtils .instantiateClass (NullValue .class );
0 commit comments