public class Jackson2HashMapper extends Object implements 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;
}
class Address {
String city;
String country;
}
Normal
Hash field | Value | |
---|---|---|
firstname | Jon | |
lastname | Snow | |
address | { "city" : "Castle Black", "country" : "The North" } |
Hash field | Value | |
---|---|---|
firstname | Jon | |
lastname | Snow | |
address.city | Castle Black | |
address.country | The North |
Constructor and Description |
---|
Jackson2HashMapper(boolean flatten)
Creates new
Jackson2HashMapper with default ObjectMapper . |
Jackson2HashMapper(com.fasterxml.jackson.databind.ObjectMapper mapper,
boolean flatten)
Creates new
Jackson2HashMapper . |
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>
Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.