Class MappingRedisConverter
java.lang.Object
org.springframework.data.redis.core.convert.MappingRedisConverter
- All Implemented Interfaces:
InitializingBean
,EntityConverter<RedisPersistentEntity<?>,
,RedisPersistentProperty, Object, RedisData> EntityReader<Object,
,RedisData> EntityWriter<Object,
,RedisData> RedisConverter
RedisConverter
implementation creating flat binary map structure out of a given domain type. Considers
Indexed
annotation for enabling helper structures for finder operations. NOTE
MappingRedisConverter
is an InitializingBean
and requires
afterPropertiesSet()
to be called.
@RedisHash("persons")
class Person {
@Id String id;
String firstname;
List<String> nicknames;
List<Person> coworkers;
Address address;
@Reference Country nationality;
}
The above is represented as:
_class=org.example.Person
id=1
firstname=rand
lastname=al'thor
coworkers.[0].firstname=mat
coworkers.[0].nicknames.[0]=prince of the ravens
coworkers.[1].firstname=perrin
coworkers.[1].address.city=two rivers
nationality=nationality:andora
- Since:
- 1.7
- Author:
- Christoph Strobl, Greg Turnquist, Mark Paluch, Golam Mazid Sajib
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Value object representing a binary Redis Hash/Object identifier composed from keyspace and object id in the form of keyspace:id.static class
Value object representing a Redis Hash/Object identifier composed from keyspace and object id in the form of keyspace:id. -
Constructor Summary
ConstructorsConstructorDescriptionMappingRedisConverter
(RedisMappingContext context) Creates newMappingRedisConverter
.MappingRedisConverter
(RedisMappingContext mappingContext, IndexResolver indexResolver, ReferenceResolver referenceResolver) Creates newMappingRedisConverter
and defaultsRedisMappingContext
when null.MappingRedisConverter
(RedisMappingContext mappingContext, IndexResolver indexResolver, ReferenceResolver referenceResolver, RedisTypeMapper typeMapper) Creates newMappingRedisConverter
and defaultsRedisMappingContext
when null. -
Method Summary
Modifier and TypeMethodDescriptionvoid
<T> T
Convert given binary representation to desired target type using the underlyingConversionService
.<R> R
protected Object
readProperty
(String path, RedisData source, RedisPersistentProperty persistentProperty) void
setCustomConversions
(CustomConversions customConversions) SetCustomConversions
to be applied.void
setIndexResolver
(IndexResolver indexResolver) void
setReferenceResolver
(ReferenceResolver referenceResolver) byte[]
Convert given source to binary representation using the underlyingConversionService
.void
protected void
writePartialUpdate
(PartialUpdate<?> update, RedisData sink)
-
Constructor Details
-
MappingRedisConverter
Creates newMappingRedisConverter
.- Parameters:
context
- can be null.- Since:
- 2.4
-
MappingRedisConverter
public MappingRedisConverter(@Nullable RedisMappingContext mappingContext, @Nullable IndexResolver indexResolver, @Nullable ReferenceResolver referenceResolver) Creates newMappingRedisConverter
and defaultsRedisMappingContext
when null.- Parameters:
mappingContext
- can be null.indexResolver
- can be null.referenceResolver
- can be not be null.
-
MappingRedisConverter
public MappingRedisConverter(@Nullable RedisMappingContext mappingContext, @Nullable IndexResolver indexResolver, @Nullable ReferenceResolver referenceResolver, @Nullable RedisTypeMapper typeMapper) Creates newMappingRedisConverter
and defaultsRedisMappingContext
when null.- Parameters:
mappingContext
- can be null.indexResolver
- can be null.referenceResolver
- can be null.typeMapper
- can be null.- Since:
- 2.1
-
-
Method Details
-
read
- Specified by:
read
in interfaceEntityReader<Object,
RedisData>
-
readProperty
@Nullable protected Object readProperty(String path, RedisData source, RedisPersistentProperty persistentProperty) -
write
- Specified by:
write
in interfaceEntityWriter<Object,
RedisData>
-
writePartialUpdate
-
toBytes
Convert given source to binary representation using the underlyingConversionService
.- Parameters:
source
-- Returns:
- Throws:
ConverterNotFoundException
-
fromBytes
Convert given binary representation to desired target type using the underlyingConversionService
.- Parameters:
source
-type
-- Returns:
- Throws:
ConverterNotFoundException
-
setIndexResolver
-
setReferenceResolver
-
setCustomConversions
SetCustomConversions
to be applied.- Parameters:
customConversions
-
-
getMappingContext
- Specified by:
getMappingContext
in interfaceEntityConverter<RedisPersistentEntity<?>,
RedisPersistentProperty, Object, RedisData> - Specified by:
getMappingContext
in interfaceRedisConverter
-
getIndexResolver
- Specified by:
getIndexResolver
in interfaceRedisConverter
- Returns:
- the configured
IndexResolver
, may be null.
-
getEntityInstantiators
- Specified by:
getEntityInstantiators
in interfaceRedisConverter
- Returns:
- the configured
EntityInstantiators
.
-
getConversionService
- Specified by:
getConversionService
in interfaceEntityConverter<RedisPersistentEntity<?>,
RedisPersistentProperty, Object, RedisData>
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-