Class GenericJackson2JsonRedisSerializer
- All Implemented Interfaces:
RedisJsonSerializer, RedisJsonSerializer.Splitter, RedisSerializer<Object>
RedisSerializer that maps objects to and from JSON using
dynamic typing.
JSON reading and writing can be customized by configuring a Jackson2ObjectReader and
Jackson2ObjectWriter.
- Since:
- 1.6
- Author:
- Christoph Strobl, Mark Paluch, Mao Shuai, John Blum, Anne Lee, Moritz Halbritter
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated, for removal: This API element is subject to removal in a future version.Builder for configuring and creating aGenericJackson2JsonRedisSerializer.Nested classes/interfaces inherited from interface RedisJsonSerializer
RedisJsonSerializer.Splitter -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.CreatesGenericJackson2JsonRedisSerializerinitialized with anObjectMapperconfigured for default typing.Deprecated, for removal: This API element is subject to removal in a future version.Setting a custom-configuredObjectMapperis one way to take further control of the JSON serialization process.GenericJackson2JsonRedisSerializer(ObjectMapper mapper, Jackson2ObjectReader reader, Jackson2ObjectWriter writer) Deprecated, for removal: This API element is subject to removal in a future version.Setting a custom-configuredObjectMapperis one way to take further control of the JSON serialization process.GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName) Deprecated, for removal: This API element is subject to removal in a future version.CreatesGenericJackson2JsonRedisSerializerinitialized with anObjectMapperconfigured for default typing using the givenname.GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName, Jackson2ObjectReader reader, Jackson2ObjectWriter writer) Deprecated, for removal: This API element is subject to removal in a future version.CreatesGenericJackson2JsonRedisSerializerinitialized with anObjectMapperconfigured for default typing using the givennamealong with the given, requiredJackson2ObjectReaderandJackson2ObjectWriterused to read/writeObjectsde/serialized as JSON. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Deprecated, for removal: This API element is subject to removal in a future version.Factory method returning a Builder used to construct and configure aGenericJackson2JsonRedisSerializer.configure(Consumer<ObjectMapper> objectMapperConfigurer) Deprecated, for removal: This API element is subject to removal in a future version.Builder method used to configure and customize the internal JacksonObjectMappercreated by thisGenericJackson2JsonRedisSerializerand used to de/serializeobjectsas JSON.deserialize(byte[] source, ResolvableType type) Deprecated, for removal: This API element is subject to removal in a future version.Deserialize the givensourceinto an instance of the type described byResolvableType.deserialize(byte @Nullable [] source) Deprecated, for removal: This API element is subject to removal in a future version.Deserialize an object from the given binary data.<T> @Nullable Tdeserialize(byte @Nullable [] source, Class<T> type) Deprecated, for removal: This API element is subject to removal in a future version.protected ObjectMapperDeprecated, for removal: This API element is subject to removal in a future version.Gets the configuredObjectMapperused internally by thisGenericJackson2JsonRedisSerializerto de/serializeobjectsas JSON.byte[]joinObject(Map<String, byte[]> members) Deprecated, for removal: This API element is subject to removal in a future version.Create a JSON object from the given members.static voidregisterNullValueSerializer(ObjectMapper objectMapper, @Nullable String typeHintPropertyName) Deprecated, for removal: This API element is subject to removal in a future version.RegisterGenericJackson2JsonRedisSerializer.NullValueSerializerin the givenObjectMapperwith an optionaltypeHintPropertyName.protected JavaTyperesolveType(byte[] source, Class<?> type) Deprecated, for removal: This API element is subject to removal in a future version.byte[]Deprecated, for removal: This API element is subject to removal in a future version.Serialize the given object to binary data.List<byte[]> splitArray(byte[] source) Deprecated, for removal: This API element is subject to removal in a future version.Extract immediate elements of a JSON array as individual JSON values.splitObject(byte[] source) Deprecated, for removal: This API element is subject to removal in a future version.Extract the immediate members of a JSON object as individual JSON values.splitter()Deprecated, for removal: This API element is subject to removal in a future version.Return aRedisJsonSerializer.Splitterfor this serializer.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RedisJsonSerializer
deserializeMethods inherited from interface RedisSerializer
canSerialize, getTargetType
-
Constructor Details
-
GenericJackson2JsonRedisSerializer
public GenericJackson2JsonRedisSerializer()Deprecated, for removal: This API element is subject to removal in a future version.CreatesGenericJackson2JsonRedisSerializerinitialized with anObjectMapperconfigured for default typing. -
GenericJackson2JsonRedisSerializer
Deprecated, for removal: This API element is subject to removal in a future version.CreatesGenericJackson2JsonRedisSerializerinitialized with anObjectMapperconfigured for default typing using the givenname.In case
nameis empty or null, thenJsonTypeInfo.Id.CLASSwill be used.- Parameters:
typeHintPropertyName-nameof the JSON property holding type information; can be null.- See Also:
-
GenericJackson2JsonRedisSerializer
public GenericJackson2JsonRedisSerializer(@Nullable String typeHintPropertyName, Jackson2ObjectReader reader, Jackson2ObjectWriter writer) Deprecated, for removal: This API element is subject to removal in a future version.CreatesGenericJackson2JsonRedisSerializerinitialized with anObjectMapperconfigured for default typing using the givennamealong with the given, requiredJackson2ObjectReaderandJackson2ObjectWriterused to read/writeObjectsde/serialized as JSON.In case
nameis empty or null, thenJsonTypeInfo.Id.CLASSwill be used.- Parameters:
typeHintPropertyName-nameof the JSON property holding type information; can be null.reader-Jackson2ObjectReaderfunction to read objects usingObjectMapper.writer-Jackson2ObjectWriterfunction to write objects usingObjectMapper.- Since:
- 3.0
- See Also:
-
GenericJackson2JsonRedisSerializer
Deprecated, for removal: This API element is subject to removal in a future version.Setting a custom-configuredObjectMapperis one way to take further control of the JSON serialization process. For example, an extendedSerializerFactorycan be configured that provides custom serializers for specific types.- Parameters:
mapper- must not be null.
-
GenericJackson2JsonRedisSerializer
public GenericJackson2JsonRedisSerializer(ObjectMapper mapper, Jackson2ObjectReader reader, Jackson2ObjectWriter writer) Deprecated, for removal: This API element is subject to removal in a future version.Setting a custom-configuredObjectMapperis one way to take further control of the JSON serialization process. For example, an extendedSerializerFactorycan be configured that provides custom serializers for specific types.- Parameters:
mapper- must not be null.reader- theJackson2ObjectReaderfunction to read objects usingObjectMapper.writer- theJackson2ObjectWriterfunction to write objects usingObjectMapper.- Since:
- 3.0
-
-
Method Details
-
builder
public static GenericJackson2JsonRedisSerializer.GenericJackson2JsonRedisSerializerBuilder builder()Deprecated, for removal: This API element is subject to removal in a future version.Factory method returning a Builder used to construct and configure aGenericJackson2JsonRedisSerializer.- Returns:
- new
GenericJackson2JsonRedisSerializer.GenericJackson2JsonRedisSerializerBuilder. - Since:
- 3.3.1
-
registerNullValueSerializer
public static void registerNullValueSerializer(ObjectMapper objectMapper, @Nullable String typeHintPropertyName) Deprecated, for removal: This API element is subject to removal in a future version.RegisterGenericJackson2JsonRedisSerializer.NullValueSerializerin the givenObjectMapperwith an optionaltypeHintPropertyName. This method should be called by code that customizesGenericJackson2JsonRedisSerializerby providing an externalObjectMapper.- Parameters:
objectMapper- the object mapper to customize.typeHintPropertyName- name of the type property. Defaults to@classif null/empty.- Since:
- 2.2
-
getObjectMapper
Deprecated, for removal: This API element is subject to removal in a future version.Gets the configuredObjectMapperused internally by thisGenericJackson2JsonRedisSerializerto de/serializeobjectsas JSON.- Returns:
- the configured
ObjectMapper.
-
serialize
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisSerializerSerialize the given object to binary data.- Specified by:
serializein interfaceRedisSerializer<Object>- Parameters:
value- object to serialize. Can be null.- Returns:
- the equivalent binary data. Can be an empty array but never null.
- Throws:
SerializationException
-
deserialize
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisSerializerDeserialize an object from the given binary data.- Specified by:
deserializein interfaceRedisSerializer<Object>- Parameters:
source- object binary representation. Can be null.- Returns:
- the equivalent object instance. Can be null.
- Throws:
SerializationException
-
deserialize
public <T> @Nullable T deserialize(byte @Nullable [] source, Class<T> type) throws SerializationException Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
deserializein interfaceRedisSerializer<Object>- Parameters:
source- array of bytes containing the JSON to deserialize; can be null.type-typeofObjectfrom which the JSON will be deserialized; must not be null.- Returns:
- null for an empty source, or an
Objectof the giventypedeserialized from the array of bytes containing JSON. - Throws:
IllegalArgumentException- if the giventypeis null.SerializationException- if the array of bytes cannot be deserialized as an instance of the giventype
-
splitter
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisJsonSerializerReturn aRedisJsonSerializer.Splitterfor this serializer.- Specified by:
splitterin interfaceRedisJsonSerializer
-
configure
Deprecated, for removal: This API element is subject to removal in a future version.Builder method used to configure and customize the internal JacksonObjectMappercreated by thisGenericJackson2JsonRedisSerializerand used to de/serializeobjectsas JSON.- Parameters:
objectMapperConfigurer-Consumerused to configure and customize the internalObjectMapper; must not be null.- Returns:
- this
GenericJackson2JsonRedisSerializer. - Throws:
IllegalArgumentException- if theConsumerused to configure and customize the internalObjectMapperis null.- Since:
- 3.1.5
-
resolveType
Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
deserialize
public @Nullable Object deserialize(byte[] source, ResolvableType type) throws SerializationException Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisJsonSerializerDeserialize the givensourceinto an instance of the type described byResolvableType.Use this variant for generic types such as
List<Person>that cannot be expressed as aClass.- Specified by:
deserializein interfaceRedisJsonSerializer- Parameters:
source- the JSON bytes to read.type- the target type.- Returns:
- the deserialized object, or null if
sourceis empty or represents JSON null. - Throws:
SerializationException- if the JSON cannot be deserialized.
-
splitArray
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisJsonSerializer.SplitterExtract immediate elements of a JSON array as individual JSON values.Note: The default implementation deserializes the array and serializes each element separately. This may change number formatting or precision. For example,
1.10may become1.1. Implementations should override this method to preserve the original bytes of each element.- Specified by:
splitArrayin interfaceRedisJsonSerializer.Splitter- Parameters:
source- the JSON array to read.- Returns:
- the JSON bytes for each element in array order, or an empty list if the array is empty.
- Throws:
SerializationException- if the source is not a JSON array or cannot be read.
-
splitObject
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisJsonSerializer.SplitterExtract the immediate members of a JSON object as individual JSON values.Note: Map keys contain the unescaped member names. Values contain the JSON bytes for each member. The default implementation deserializes the object and serializes each member value separately. See
RedisJsonSerializer.Splitter.splitArray(byte[])for the effect on number formatting and precision.- Specified by:
splitObjectin interfaceRedisJsonSerializer.Splitter- Parameters:
source- the JSON object to read.- Returns:
- the members in source order, or an empty map if the object is empty.
- Throws:
SerializationException- if the source is not a JSON object or cannot be read.
-
joinObject
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:RedisJsonSerializer.SplitterCreate a JSON object from the given members.Map keys supply the member names, which are escaped as needed. Each value must contain a valid JSON value. Members are written in map iteration order.
Note: The default implementation deserializes the member values and serializes the resulting object. See
RedisJsonSerializer.Splitter.splitArray(byte[])for the effect on number formatting and precision. Implementations can override this method to preserve the supplied JSON bytes for each value.- Specified by:
joinObjectin interfaceRedisJsonSerializer.Splitter- Parameters:
members- the member names and their JSON bytes.- Returns:
- the JSON object as bytes, or the representation of
{}if the map is empty. - Throws:
SerializationException- if the object cannot be written.- See Also:
-
GenericJacksonJsonRedisSerializer