Class MappingPdxSerializer

java.lang.Object
org.springframework.data.gemfire.mapping.MappingPdxSerializer
All Implemented Interfaces:
org.apache.geode.pdx.PdxSerializer, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class MappingPdxSerializer extends Object implements org.apache.geode.pdx.PdxSerializer, org.springframework.context.ApplicationContextAware
PdxSerializer implementation using the Spring Data for Apache Geode GemfireMappingContext to read (deserialize) and write (serialize) entities from and to PDX.
Since:
1.2.0
See Also:
  • PdxReader
  • PdxSerializer
  • PdxWriter
  • ApplicationContext
  • ApplicationContextAware
  • ConversionService
  • Filter
  • PersistentEntity
  • PersistentProperty
  • PersistentPropertyAccessor
  • PropertyHandler
  • ConvertingPropertyAccessor
  • EntityInstantiator
  • EntityInstantiators
  • PersistentEntityParameterValueProvider
  • Field Details

  • Constructor Details

  • Method Details

    • newMappingPdxSerializer

      @NonNull public static MappingPdxSerializer newMappingPdxSerializer()
      Factory method used to construct a new instance of MappingPdxSerializer initialized with a provided GemfireMappingContext and default ConversionService.
      Returns:
      a new instance of MappingPdxSerializer.
      See Also:
    • create

      @NonNull public static MappingPdxSerializer create(@Nullable org.springframework.core.convert.ConversionService conversionService)
      Factory method used to construct a new instance of MappingPdxSerializer initialized with the given ConversionService and a provided GemfireMappingContext.
      Parameters:
      conversionService - ConversionService used to convert persistent values to entity properties.
      Returns:
      a new instance of MappingPdxSerializer initialized with the given ConversionService.
      See Also:
    • create

      @NonNull public static MappingPdxSerializer create(@Nullable GemfireMappingContext mappingContext)
      Factory method used to construct a new instance of MappingPdxSerializer initialized with the given mapping context supplying entity mapping meta-data, using a provided, default ConversionService.
      Parameters:
      mappingContext - GemfireMappingContext used to supply entity mapping meta-data.
      Returns:
      a new instance of MappingPdxSerializer initialized with the given mapping context.
      See Also:
    • create

      @NonNull public static MappingPdxSerializer create(@Nullable GemfireMappingContext mappingContext, @Nullable org.springframework.core.convert.ConversionService conversionService)
      Factory method used to construct a new instance of MappingPdxSerializer initialized with the given mapping context and conversion service. If either the mapping context or the conversion service are null, then this factory method will provide default instances for each.
      Parameters:
      mappingContext - GemfireMappingContext used to map between application domain model object types and PDX serialized bytes based on the entity's mapping meta-data.
      conversionService - ConversionService used to convert persistent values to entity properties.
      Returns:
      an initialized instance of the MappingPdxSerializer.
      See Also:
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Configures a reference to the Spring ApplicationContext.
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Parameters:
      applicationContext - reference to the Spring ApplicationContext.
      Throws:
      org.springframework.beans.BeansException
      See Also:
      • ApplicationContext
    • getConversionService

      @NonNull protected org.springframework.core.convert.ConversionService getConversionService()
      Returns a reference to the configured ConversionService used to convert data store types to application domain object types.
      Returns:
      a reference to the configured ConversionService.
      See Also:
      • ConversionService
    • setCustomPdxSerializers

      public void setCustomPdxSerializers(Map<?,org.apache.geode.pdx.PdxSerializer> customPdxSerializers)
      Configures custom PDX serializers used to customize the serialization for specific application domain types.
      Parameters:
      customPdxSerializers - mapping containing custom PDX serializers used to customize the serialization of specific application domain types.
      Throws:
      IllegalArgumentException - if the custom PDX serializer mapping is null.
      See Also:
      • PdxSerializer
      • Map
    • getCustomPdxSerializers

      @NonNull protected Map<?,org.apache.geode.pdx.PdxSerializer> getCustomPdxSerializers()
      Returns a mapping of application domain types to custom PDX serializers used to customize the serialization for specific application domain types.
      Returns:
      a mapping of application domain types to custom PDX serializers.
      See Also:
      • PdxSerializer
      • Map
    • setEntityInstantiators

      public void setEntityInstantiators(@NonNull org.springframework.data.mapping.model.EntityInstantiators entityInstantiators)
      Configures the EntityInstantiators used to create the instances read by this PdxSerializer.
      Parameters:
      entityInstantiators - EntityInstantiators used to create the instances read by this PdxSerializer; must not be null.
      See Also:
      • EntityInstantiator
    • setEntityInstantiators

      public void setEntityInstantiators(@NonNull Map<Class<?>,org.springframework.data.mapping.model.EntityInstantiator> gemfireInstantiators)
      Configures the EntityInstantiators used to create the instances read by this PdxSerializer.
      Parameters:
      gemfireInstantiators - mapping of types to EntityInstantiator objects; must not be null.
      See Also:
      • EntityInstantiator
      • Map
    • getEntityInstantiators

      protected org.springframework.data.mapping.model.EntityInstantiators getEntityInstantiators()
      Returns the configured EntityInstantiators handling instantiation for GemFire persistent entities.
      Returns:
      the configured EntityInstantiators handling instantiation for GemFire persistent entities.
      See Also:
      • EntityInstantiators
    • getLogger

      @NonNull protected org.slf4j.Logger getLogger()
      Returns a reference to the configured Logger used to log messages about the functions of this PdxSerializer.
      Returns:
      a reference to the configured Logger.
      See Also:
      • Logger
    • getMappingContext

      @NonNull protected GemfireMappingContext getMappingContext()
      Returns a reference to the configured mapping context used to handling mapping logic between GemFire persistent entities and application domain object types.
      Returns:
      a reference to the configured mapping context for Pivotal GemFire.
      See Also:
    • getPersistentEntity

      protected GemfirePersistentEntity<?> getPersistentEntity(@NonNull Object entity)
      Looks up and returns the PersistentEntity meta-data for the given entity object.
      Parameters:
      entity - actual persistent entity, application domain object.
      Returns:
      the PersistentEntity meta-data for the given entity object.
      See Also:
    • getPersistentEntity

      protected GemfirePersistentEntity<?> getPersistentEntity(@NonNull Class<?> entityType)
      Looks up and returns the PersistentEntity meta-data for the given entity Class type.
      Parameters:
      entityType - Class type of the actual persistent entity, application domain object Class.
      Returns:
      the PersistentEntity meta-data for the given entity Class type.
      See Also:
    • setExcludeTypeFilters

      public void setExcludeTypeFilters(@Nullable Predicate<Class<?>> excludeTypeFilters)
      Sets the type filters used to exclude (a.k.a. filter) types serializable by this PDX serializer. This operation is null-safe and rather than overriding the existing excluded type filters, this set operation combines the given exclude type filters with the exiting excluded type filters joined by and.
      Parameters:
      excludeTypeFilters - type filters used to exclude/filter types serializable by this PDX serializer.
      See Also:
    • setIncludeTypeFilters

      public void setIncludeTypeFilters(@Nullable Predicate<Class<?>> includeTypeFilters)
      Sets the type filters used to include types serializable by this PDX serializer. This operation is null-safe and rather than overriding the existing included type filters, this set operation combines the given include type filters with the exiting included type filters joined by or.
      Parameters:
      includeTypeFilters - type filters used to include types serializable by this PDX serializer.
      See Also:
    • getTypeFilters

      protected Predicate<Class<?>> getTypeFilters()
      Returns the type filters used to filter types serializable by this PdxSerializer.
      Returns:
      the resolved type filter.
      See Also:
    • register

      public void register(@NonNull MappingPdxSerializer.PdxSerializerResolver pdxSerializerResolver)
      Registers the given MappingPdxSerializer.PdxSerializerResolver, which will be used to resolve a custom PdxSerializer for a entity property. The strategy, or criteria used to resolve the custom PdxSerializer is up to the individual resolve and can be based on things like the property type, or fully-qualified property name, etc.
      Parameters:
      pdxSerializerResolver - MappingPdxSerializer.PdxSerializerResolver used to resolve a custom PdxSerializer for a entity property.
    • fromData

      public Object fromData(@NonNull Class<?> type, @NonNull org.apache.geode.pdx.PdxReader pdxReader)
      Deserializes (reads) an Object of type from PDX using the PdxReader.
      Specified by:
      fromData in interface org.apache.geode.pdx.PdxSerializer
      Parameters:
      type - desired Class type of the Object; must not be null.
      pdxReader - PdxReader used to deserialize the PDX bytes back into an Object of the desired Class type; must not be null.
      Returns:
      an Object of Class type deserialized from PDX or null if an Object of Class type cannot be deserialized from PDX.
      See Also:
    • toData

      public boolean toData(@Nullable Object value, @NonNull org.apache.geode.pdx.PdxWriter pdxWriter)
      Serialize (write) the given Object to PDX.
      Specified by:
      toData in interface org.apache.geode.pdx.PdxSerializer
      Parameters:
      value - Object to serialize.
      pdxWriter - PdxWriter used to serialize the given Object to PDX.
      Returns:
      a boolean value indicating whether this PdxSerializer was able to serialize the given Object to PDX.
      See Also:
    • resolveCustomPdxSerializer

      @Nullable protected org.apache.geode.pdx.PdxSerializer resolveCustomPdxSerializer(@NonNull org.springframework.data.mapping.PersistentProperty<?> property)
      Returns a custom PdxSerializer for the given PersistentEntity PersistentProperty.
      Parameters:
      property - PersistentProperty of the entity used to resolve a custom PdxSerializer.
      Returns:
      a custom PdxSerializer for the given PersistentEntity PersistentProperty, or null if no custom PdxSerializer could be found.
      See Also:
    • resolveEntityInstantiator

      protected org.springframework.data.mapping.model.EntityInstantiator resolveEntityInstantiator(@NonNull org.springframework.data.mapping.PersistentEntity entity)
      Looks up and returns a registered EntityInstantiator used to construct and initialize an instance of an object defined by the given PersistentEntity (meta-data).
      Parameters:
      entity - PersistentEntity object used to lookup a custom, registered EntityInstantiator for the entity.
      Returns:
      an EntityInstantiator for the given PersistentEntity.
      See Also:
      • EntityInstantiator
      • PersistentEntity