Class ObjectHashMapper

java.lang.Object
org.springframework.data.redis.hash.ObjectHashMapper
All Implemented Interfaces:
HashMapper<Object,byte[],byte[]>

public class ObjectHashMapper extends Object implements HashMapper<Object,byte[],byte[]>
HashMapper based on MappingRedisConverter. Supports nested properties and simple types like String.
 
 class Person {

   String firstname;
   String lastname;

   List<String> nicknames;
   List<Person> coworkers;

   Address address;
 }
 
 
The above is represented as:
 
 _class=org.example.Person
 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
 
 
Since:
1.8
Author:
Christoph Strobl, Mark Paluch
  • Constructor Details

  • Method Details

    • getSharedInstance

      public static ObjectHashMapper getSharedInstance()
      Return a shared default ObjectHashMapper instance, lazily building it once needed.

      NOTE: We highly recommend constructing individual ObjectHashMapper instances for customization purposes. This accessor is only meant as a fallback for code paths which need simple type coercion but cannot access a longer-lived ObjectHashMapper instance any other way.

      Returns:
      the shared ObjectHashMapper instance (never null).
      Since:
      2.4
    • toHash

      public Map<byte[],byte[]> toHash(Object source)
      Description copied from interface: HashMapper
      Convert an object to a map that can be used with Redis hashes.
      Specified by:
      toHash in interface HashMapper<Object,byte[],byte[]>
      Returns:
    • fromHash

      public Object fromHash(Map<byte[],byte[]> hash)
      Description copied from interface: HashMapper
      Convert a hash (map) to an object.
      Specified by:
      fromHash in interface HashMapper<Object,byte[],byte[]>
      Returns:
    • fromHash

      public <T> T fromHash(Map<byte[],byte[]> hash, Class<T> type)
      Convert a hash (map) to an object and return the casted result.
      Type Parameters:
      T -
      Parameters:
      hash -
      type -
      Returns: