spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

MappingRedisConverter does not support collection-like values in maps [DATAREDIS-722]

Open spring-projects-issues opened this issue 8 years ago • 4 comments

Jonathan ROQUES opened DATAREDIS-722 and commented

In a model class (called MyClass) I have an attribute as :

private Map<String, Set<String>> attr = new HashMap<>();

When using :

new ObjectHashMapper().toHash(myClassInstance);

It throw a NullPointerException :

java.lang.NullPointerException
	at org.springframework.data.redis.core.convert.MappingRedisConverter.writeInternal(MappingRedisConverter.java:556)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.writeMap(MappingRedisConverter.java:787)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.access$700(MappingRedisConverter.java:114)
	at org.springframework.data.redis.core.convert.MappingRedisConverter$3.doWithPersistentProperty(MappingRedisConverter.java:572)
	at org.springframework.data.redis.core.convert.MappingRedisConverter$3.doWithPersistentProperty(MappingRedisConverter.java:558)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.writeInternal(MappingRedisConverter.java:558)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.writeMap(MappingRedisConverter.java:787)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.access$700(MappingRedisConverter.java:114)
	at org.springframework.data.redis.core.convert.MappingRedisConverter$3.doWithPersistentProperty(MappingRedisConverter.java:572)
	at org.springframework.data.redis.core.convert.MappingRedisConverter$3.doWithPersistentProperty(MappingRedisConverter.java:558)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.writeInternal(MappingRedisConverter.java:558)
	at org.springframework.data.redis.core.convert.MappingRedisConverter.write(MappingRedisConverter.java:380)
	at org.springframework.data.redis.hash.ObjectHashMapper.toHash(ObjectHashMapper.java:107)

It seems that because the HashSet is backed by a Map with null values, MappingRedisConverter has some trouble to deal with Sets in Map


Affects: 1.8.8 (Ingalls SR8)

spring-projects-issues avatar Oct 27 '17 08:10 spring-projects-issues

Mark Paluch commented

We currently do not support Collection-like value type in maps. Adding support for collection values could serialize your data structure to:

attr.[foo][0]=bar
attr.[foo][1]=baz
…

spring-projects-issues avatar Nov 02 '17 14:11 spring-projects-issues

Jonathan ROQUES commented

Ok, is this limitation mentioned in spring data redis documentation ? If not It is worth adding it to avoid misusage, isn't it ?

spring-projects-issues avatar Nov 02 '17 14:11 spring-projects-issues

Mark Paluch commented

It's mentioned by its absence in Object to Hash Mapping. We usually document things that are supported, not the other way round.

Adding support could make sense, need to check with Christoph Strobl

spring-projects-issues avatar Nov 02 '17 14:11 spring-projects-issues

Jonathan ROQUES commented

Indeed, but as Maps are supporter and Lists are supported too it makes sense to assume that Map with List values are supported as well :) But I got your point too...

Thanks

spring-projects-issues avatar Nov 02 '17 15:11 spring-projects-issues