Class Jackson2HashMapper
java.lang.Object
org.springframework.data.redis.hash.Jackson2HashMapper
- All Implemented Interfaces:
HashMapper<Object,String, Object>
ObjectMapper based HashMapper implementation that allows flattening. Given an entity Person
with an Address like below the flattening will create individual hash entries for all nested properties and
resolve complex types into simple types, as far as possible.
Flattening requires all property names to not interfere with JSON paths. Using dots or brackets in map keys or as property names is not supported using flattening. The resulting hash cannot be mapped back into an Object.
Example
class Person {
String firstname;
String lastname;
Address address;
Date date;
LocalDateTime localDateTime;
}
class Address {
String city;
String country;
}
Normal
| Hash field | Value |
|---|---|
| firstname | Jon |
| lastname | Snow |
| address | { "city" : "Castle Black", "country" : "The North" } |
| date | 1561543964015 |
| localDateTime | 2018-01-02T12:13:14 |
Flat
| Hash field | Value |
|---|---|
| firstname | Jon |
| lastname | Snow |
| address.city | Castle Black |
| address.country | The North |
| date | 1561543964015 |
| localDateTime | 2018-01-02T12:13:14 |
- Since:
- 1.8
- Author:
- Christoph Strobl, Mark Paluch, John Blum
-
Constructor Summary
ConstructorsConstructorDescriptionJackson2HashMapper(boolean flatten) Creates newJackson2HashMapperwith a defaultObjectMapper.Jackson2HashMapper(com.fasterxml.jackson.databind.ObjectMapper mapper, boolean flatten) Creates newJackson2HashMapperinitialized with a custom JacksonObjectMapper. -
Method Summary
-
Constructor Details
-
Jackson2HashMapper
public Jackson2HashMapper(boolean flatten) Creates newJackson2HashMapperwith a defaultObjectMapper.- Parameters:
flatten- boolean used to configure whether JSON de/serializedObjectproperties will be un/flattened using dot notation, or whether to retain the hierarchical node structure created by Jackson.
-
Jackson2HashMapper
public Jackson2HashMapper(com.fasterxml.jackson.databind.ObjectMapper mapper, boolean flatten) Creates newJackson2HashMapperinitialized with a custom JacksonObjectMapper.
-
-
Method Details
-
toHash
Description copied from interface:HashMapperConvert anobjectto a map that can be used with Redis hashes.- Specified by:
toHashin interfaceHashMapper<Object,String, Object> - Returns:
-
fromHash
Description copied from interface:HashMapperConvert ahash(map) to an object.- Specified by:
fromHashin interfaceHashMapper<Object,String, Object> - Returns:
-