Class MappingPdxSerializer
java.lang.Object
org.springframework.data.gemfire.mapping.MappingPdxSerializer
- All Implemented Interfaces:
PdxSerializer,Aware,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
- Author:
- Oliver Gierke, David Turanski, John Blum
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic enumstatic enum -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance ofMappingPdxSerializerusing a defaultGemfireMappingContextandDefaultConversionService.MappingPdxSerializer(GemfireMappingContext mappingContext, ConversionService conversionService) Constructs a new instance ofMappingPdxSerializerinitialized with the givenGemfireMappingContextandConversionService. -
Method Summary
Modifier and TypeMethodDescriptionstatic MappingPdxSerializercreate(ConversionService conversionService) Factory method used to construct a new instance ofMappingPdxSerializerinitialized with the givenConversionServiceand a providedGemfireMappingContext.static MappingPdxSerializercreate(GemfireMappingContext mappingContext) Factory method used to construct a new instance ofMappingPdxSerializerinitialized with the givenmapping contextsupplying entity mapping meta-data, using a provided, defaultConversionService.static MappingPdxSerializercreate(GemfireMappingContext mappingContext, ConversionService conversionService) Factory method used to construct a new instance ofMappingPdxSerializerinitialized with the givenmapping contextandconversion service.protected ConversionServiceReturns a reference to the configuredConversionServiceused to convert data store types to application domain object types.protected Map<?,PdxSerializer> Returns amappingof applicationdomain typesto customPDX serializersused to customize the serialization for specific applicationdomain types.protected EntityInstantiatorsReturns the configuredEntityInstantiatorshandling instantiation for GemFire persistent entities.protected org.slf4j.LoggerReturns a reference to the configuredLoggerused to logmessagesabout the functions of thisPdxSerializer.protected GemfireMappingContextReturns a reference to the configuredmapping contextused to handling mapping logic between GemFire persistent entities and application domain objecttypes.protected GemfirePersistentEntity<?>getPersistentEntity(Class<?> entityType) Looks up and returns thePersistentEntitymeta-data for the given entityClasstype.protected GemfirePersistentEntity<?>getPersistentEntity(Object entity) Looks up and returns thePersistentEntitymeta-data for the given entity object.static MappingPdxSerializerFactory method used to construct a new instance ofMappingPdxSerializerinitialized with a providedGemfireMappingContextand defaultConversionService.voidregister(MappingPdxSerializer.PdxSerializerResolver pdxSerializerResolver) Registers the givenMappingPdxSerializer.PdxSerializerResolver, which will be used to resolve a customPdxSerializerfor a entity property.protected PdxSerializerresolveCustomPdxSerializer(PersistentProperty<?> property) protected EntityInstantiatorLooks up and returns a registeredEntityInstantiatorused to construct and initialize an instance of an object defined by the givenPersistentEntity(meta-data).voidsetApplicationContext(ApplicationContext applicationContext) Configures a reference to the SpringApplicationContext.voidsetCustomPdxSerializers(Map<?, PdxSerializer> customPdxSerializers) Configures customPDX serializersused to customize the serialization for specific applicationdomain types.voidsetEntityInstantiators(Map<Class<?>, EntityInstantiator> gemfireInstantiators) Configures theEntityInstantiatorsused to create the instances read by thisPdxSerializer.voidsetEntityInstantiators(EntityInstantiators entityInstantiators) Configures theEntityInstantiatorsused to create the instances read by thisPdxSerializer.voidsetExcludeTypeFilters(Predicate<Class<?>> excludeTypeFilters) voidsetIncludeTypeFilters(Predicate<Class<?>> includeTypeFilters) booleanSerialize (write) the givenObjectto PDX.
-
Field Details
-
JAVA_PACKAGE_NAME
- See Also:
-
COM_GEMSTONE_GEMFIRE_PACKAGE_NAME
- See Also:
-
ORG_APACHE_GEODE_PACKAGE_NAME
- See Also:
-
ORG_SPRINGFRAMEWORK_PACKAGE_NAME
- See Also:
-
-
Constructor Details
-
MappingPdxSerializer
public MappingPdxSerializer()Constructs a new instance ofMappingPdxSerializerusing a defaultGemfireMappingContextandDefaultConversionService.- See Also:
-
newConversionService()newMappingContext()DefaultConversionServiceGemfireMappingContext
-
MappingPdxSerializer
public MappingPdxSerializer(GemfireMappingContext mappingContext, ConversionService conversionService) Constructs a new instance ofMappingPdxSerializerinitialized with the givenGemfireMappingContextandConversionService.- Parameters:
mappingContext-GemfireMappingContextused by theMappingPdxSerializerto map between application domain object types and PDX serialized bytes based on the entity mapping meta-data.conversionService-ConversionServiceused by theMappingPdxSerializerto convert PDX serialized data to application object property types.- Throws:
IllegalArgumentException- if either theGemfireMappingContextor theConversionServiceis null.
-
-
Method Details
-
newMappingPdxSerializer
Factory method used to construct a new instance ofMappingPdxSerializerinitialized with a providedGemfireMappingContextand defaultConversionService.- Returns:
- a new instance of
MappingPdxSerializer. - See Also:
-
create(GemfireMappingContext, ConversionService)newMappingContext()newConversionService()
-
create
Factory method used to construct a new instance ofMappingPdxSerializerinitialized with the givenConversionServiceand a providedGemfireMappingContext.- Parameters:
conversionService-ConversionServiceused to convert persistent values to entity properties.- Returns:
- a new instance of
MappingPdxSerializerinitialized with the givenConversionService. - See Also:
-
ConversionServicecreate(GemfireMappingContext, ConversionService)newMappingContext()
-
create
Factory method used to construct a new instance ofMappingPdxSerializerinitialized with the givenmapping contextsupplying entity mapping meta-data, using a provided, defaultConversionService.- Parameters:
mappingContext-GemfireMappingContextused to supply entity mapping meta-data.- Returns:
- a new instance of
MappingPdxSerializerinitialized with the givenmapping context. - See Also:
-
GemfireMappingContextcreate(GemfireMappingContext, ConversionService)newConversionService()
-
create
@NonNull public static MappingPdxSerializer create(@Nullable GemfireMappingContext mappingContext, @Nullable ConversionService conversionService) Factory method used to construct a new instance ofMappingPdxSerializerinitialized with the givenmapping contextandconversion service. If either themapping contextor theconversion serviceare null, then this factory method will provide default instances for each.- Parameters:
mappingContext-GemfireMappingContextused to map between application domain model object types and PDX serialized bytes based on the entity's mapping meta-data.conversionService-ConversionServiceused to convert persistent values to entity properties.- Returns:
- an initialized instance of the
MappingPdxSerializer. - See Also:
-
setApplicationContext
Configures a reference to the SpringApplicationContext.- Specified by:
setApplicationContextin interfaceApplicationContextAware- Parameters:
applicationContext- reference to the SpringApplicationContext.- Throws:
BeansException- See Also:
-
getConversionService
Returns a reference to the configuredConversionServiceused to convert data store types to application domain object types.- Returns:
- a reference to the configured
ConversionService. - See Also:
-
setCustomPdxSerializers
Configures customPDX serializersused to customize the serialization for specific applicationdomain types.- Parameters:
customPdxSerializers-mappingcontaining customPDX serializersused to customize the serialization of specific applicationdomain types.- Throws:
IllegalArgumentException- if thecustom PDX serializer mappingis null.- See Also:
-
getCustomPdxSerializers
Returns amappingof applicationdomain typesto customPDX serializersused to customize the serialization for specific applicationdomain types.- Returns:
- a
mappingof applicationdomain typesto customPDX serializers. - See Also:
-
setEntityInstantiators
Configures theEntityInstantiatorsused to create the instances read by thisPdxSerializer.- Parameters:
entityInstantiators-EntityInstantiatorsused to create the instances read by thisPdxSerializer; must not be null.- See Also:
-
setEntityInstantiators
Configures theEntityInstantiatorsused to create the instances read by thisPdxSerializer.- Parameters:
gemfireInstantiators- mapping oftypestoEntityInstantiatorobjects; must not be null.- See Also:
-
getEntityInstantiators
Returns the configuredEntityInstantiatorshandling instantiation for GemFire persistent entities.- Returns:
- the configured
EntityInstantiatorshandling instantiation for GemFire persistent entities. - See Also:
-
getLogger
Returns a reference to the configuredLoggerused to logmessagesabout the functions of thisPdxSerializer.- Returns:
- a reference to the configured
Logger. - See Also:
-
Logger
-
getMappingContext
Returns a reference to the configuredmapping contextused to handling mapping logic between GemFire persistent entities and application domain objecttypes.- Returns:
- a reference to the configured
mapping contextfor Pivotal GemFire. - See Also:
-
getPersistentEntity
Looks up and returns thePersistentEntitymeta-data for the given entity object.- Parameters:
entity- actual persistent entity, application domain object.- Returns:
- the
PersistentEntitymeta-data for the given entity object. - See Also:
-
getPersistentEntity
Looks up and returns thePersistentEntitymeta-data for the given entityClasstype.- Parameters:
entityType-Classtype of the actual persistent entity, application domain objectClass.- Returns:
- the
PersistentEntitymeta-data for the given entityClasstype. - See Also:
-
setExcludeTypeFilters
Sets thetype filtersused to exclude (a.k.a. filter)typesserializable by thisPDX serializer. This operation is null-safe and rather than overriding the existingexcluded type filters, this set operation combines the givenexclude type filterswith the exitingexcluded type filtersjoined by and.- Parameters:
excludeTypeFilters-type filtersused to exclude/filtertypesserializable by thisPDX serializer.- See Also:
-
setIncludeTypeFilters
Sets thetype filtersused to includetypesserializable by thisPDX serializer. This operation is null-safe and rather than overriding the existingincluded type filters, this set operation combines the giveninclude type filterswith the exitingincluded type filtersjoined by or.- Parameters:
includeTypeFilters-type filtersused to includetypesserializable by thisPDX serializer.- See Also:
-
getTypeFilters
- Returns:
- the resolved
type filter. - See Also:
-
register
Registers the givenMappingPdxSerializer.PdxSerializerResolver, which will be used to resolve a customPdxSerializerfor a entity property. The strategy, or criteria used to resolve the customPdxSerializeris up to the individual resolve and can be based on things like the property type, or fully-qualified property name, etc.- Parameters:
pdxSerializerResolver-MappingPdxSerializer.PdxSerializerResolverused to resolve a customPdxSerializerfor a entity property.
-
fromData
- Specified by:
fromDatain interfacePdxSerializer- Parameters:
type- desiredClasstype of theObject; must not be null.pdxReader-PdxReaderused to deserialize the PDX bytes back into anObjectof the desiredClasstype; must not be null.- Returns:
- an
ObjectofClasstype deserialized from PDX or null if anObjectofClasstype cannot be deserialized from PDX. - See Also:
-
PdxReaderdoFromData(Class, PdxReader)getTypeFilters()ClassObject
-
toData
Serialize (write) the givenObjectto PDX.- Specified by:
toDatain interfacePdxSerializer- Parameters:
value-Objectto serialize.pdxWriter-PdxWriterused to serialize the givenObjectto PDX.- Returns:
- a boolean value indicating whether this
PdxSerializerwas able to serialize the givenObjectto PDX. - See Also:
-
PdxWriterdoToData(Object, PdxWriter)getTypeFilters()Object
-
resolveCustomPdxSerializer
@Nullable protected PdxSerializer resolveCustomPdxSerializer(@NonNull PersistentProperty<?> property) - Parameters:
property-PersistentPropertyof the entity used to resolve a customPdxSerializer.- Returns:
- a custom
PdxSerializerfor the givenPersistentEntityPersistentProperty, or null if no customPdxSerializercould be found. - See Also:
-
resolveEntityInstantiator
Looks up and returns a registeredEntityInstantiatorused to construct and initialize an instance of an object defined by the givenPersistentEntity(meta-data).- Parameters:
entity-PersistentEntityobject used to lookup a custom, registeredEntityInstantiatorfor the entity.- Returns:
- an
EntityInstantiatorfor the givenPersistentEntity. - See Also:
-