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 .ser .std .StdSerializer ;
43
46
import org .junit .jupiter .api .Test ;
44
47
import org .mockito .Mockito ;
45
48
@@ -420,7 +423,7 @@ void deserializesJavaTimeFrimBytes() {
420
423
}
421
424
422
425
@ Test // GH-2601
423
- public void internalObjectMapperCustomization () {
426
+ void internalObjectMapperCustomization () {
424
427
425
428
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer ();
426
429
@@ -438,14 +441,34 @@ public void internalObjectMapperCustomization() {
438
441
}
439
442
440
443
@ Test // GH-2601
441
- public void configureWithNullConsumerThrowsIllegalArgumentException () {
444
+ void configureWithNullConsumerThrowsIllegalArgumentException () {
442
445
443
446
assertThatIllegalArgumentException ()
444
447
.isThrownBy (() -> new GenericJackson2JsonRedisSerializer ().configure (null ))
445
448
.withMessage ("Consumer used to configure and customize ObjectMapper must not be null" )
446
449
.withNoCause ();
447
450
}
448
451
452
+ @ Test
453
+ void customSerializeAndDeserializeNullValue () {
454
+
455
+ GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer ();
456
+ String expected = "null" ;
457
+
458
+ serializer .registerCustomNullValueSerializer (new StdSerializer <>(String .class ) {
459
+ @ Override
460
+ public void serialize (String value , JsonGenerator gen , SerializerProvider provider ) throws IOException {
461
+ gen .writeRawValue (expected );
462
+ }
463
+ });
464
+
465
+ byte [] serializedValue = serializer .serialize (expected );
466
+ assertThat (serializedValue ).isNotNull ();
467
+
468
+ Object deserializedValue = serializer .deserialize (serializedValue );
469
+ assertThat (deserializedValue ).isNull ();
470
+ }
471
+
449
472
private static void serializeAndDeserializeNullValue (GenericJackson2JsonRedisSerializer serializer ) {
450
473
451
474
NullValue nv = BeanUtils .instantiateClass (NullValue .class );
0 commit comments