public class Jackson2HashMapper extends Object implements HashMapper<Object,String,Object>, HashObjectReader<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.
class Person { String firstname; String lastname; Address address; Date date; LocalDateTime localDateTime; } class Address { String city; String country; }
Hash field | Value |
---|---|
firstname | Jon |
lastname | Snow |
address | { "city" : "Castle Black", "country" : "The North" } |
date | 1561543964015 |
localDateTime | 2018-01-02T12:13:14 |
Hash field | Value |
---|---|
firstname | Jon |
lastname | Snow |
address.city | Castle Black |
address.country | The North |
date | 1561543964015 |
localDateTime | 2018-01-02T12:13:14 |
Constructor and Description |
---|
Jackson2HashMapper(boolean flatten)
Creates new
Jackson2HashMapper with default ObjectMapper . |
Jackson2HashMapper(com.fasterxml.jackson.databind.ObjectMapper mapper,
boolean flatten)
Creates new
Jackson2HashMapper . |
Modifier and Type | Method and Description |
---|---|
<R> R |
fromHash(Class<R> type,
Map<String,Object> hash)
Materialize an object of the
type from a hash . |
Object |
fromHash(Map<String,Object> hash)
Convert a
hash (map) to an object. |
Map<String,Object> |
toHash(Object source)
Convert an
object to a map that can be used with Redis hashes. |
public Jackson2HashMapper(boolean flatten)
Jackson2HashMapper
with default ObjectMapper
.flatten
- public Jackson2HashMapper(com.fasterxml.jackson.databind.ObjectMapper mapper, boolean flatten)
Jackson2HashMapper
.mapper
- must not be null.flatten
- public Map<String,Object> toHash(Object source)
HashMapper
object
to a map that can be used with Redis hashes.toHash
in interface HashMapper<Object,String,Object>
public Object fromHash(Map<String,Object> hash)
HashMapper
hash
(map) to an object.fromHash
in interface HashMapper<Object,String,Object>
public <R> R fromHash(Class<R> type, Map<String,Object> hash)
HashObjectReader
type
from a hash
.fromHash
in interface HashObjectReader<String,Object>
hash
- must not be null.hash
.Copyright © 2011–2023 Pivotal Software, Inc.. All rights reserved.