Class MappingVaultConverter
java.lang.Object
org.springframework.vault.repository.convert.AbstractVaultConverter
org.springframework.vault.repository.convert.MappingVaultConverter
- All Implemented Interfaces:
InitializingBean
,EntityConverter<VaultPersistentEntity<?>,
,VaultPersistentProperty, Object, SecretDocument> EntityReader<Object,
,SecretDocument> EntityWriter<Object,
,SecretDocument> VaultConverter
VaultConverter
that uses a MappingContext
to do sophisticated mapping
of domain objects to SecretDocument
. This converter converts between Map-typed
representations and domain objects without use of a JSON library.
SecretDocument
is the input to JSON mapping to exchange secrets with Vault.- Since:
- 2.0
- Author:
- Mark Paluch
-
Field Summary
Fields inherited from class org.springframework.vault.repository.convert.AbstractVaultConverter
conversions, conversionService, instantiators
-
Constructor Summary
ConstructorDescriptionMappingVaultConverter
(MappingContext<? extends VaultPersistentEntity<?>, VaultPersistentProperty> mappingContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCustomTypeKeyIfNecessary
(TypeInformation<?> type, Object value, org.springframework.vault.repository.convert.SecretDocumentAccessor accessor) Adds custom type information to the givenSecretDocument
if necessary.createCollection
(Collection<?> collection, VaultPersistentProperty property) Writes the givenCollection
using the givenVaultPersistentProperty
information.createMap
(Map<Object, Object> map, VaultPersistentProperty property) Writes the givenMap
using the givenVaultPersistentProperty
information.MappingContext<? extends VaultPersistentEntity<?>,
VaultPersistentProperty> <S> S
read
(Class<S> type, SecretDocument source) readMap
(TypeInformation<?> type, Map<String, Object> sourceMap) void
setTypeMapper
(VaultTypeMapper typeMapper) Configures theVaultTypeMapper
to be used to add type information toSecretDocument
s created by the converter and how to lookup type information fromSecretDocument
s when reading them.void
write
(Object source, SecretDocument sink) protected void
writeInternal
(Object obj, org.springframework.vault.repository.convert.SecretDocumentAccessor sink, TypeInformation<?> typeHint) Internal write conversion method which should be used for nested invocations.protected void
writeInternal
(Object obj, org.springframework.vault.repository.convert.SecretDocumentAccessor sink, VaultPersistentEntity<?> entity) writeMapInternal
(Map<Object, Object> obj, Map<String, Object> bson, TypeInformation<?> propertyType) protected void
writePropertyInternal
(Object obj, org.springframework.vault.repository.convert.SecretDocumentAccessor accessor, VaultPersistentProperty prop) Methods inherited from class org.springframework.vault.repository.convert.AbstractVaultConverter
afterPropertiesSet, getConversionService, setCustomConversions, setInstantiators
-
Constructor Details
-
MappingVaultConverter
public MappingVaultConverter(MappingContext<? extends VaultPersistentEntity<?>, VaultPersistentProperty> mappingContext)
-
-
Method Details
-
setTypeMapper
Configures theVaultTypeMapper
to be used to add type information toSecretDocument
s created by the converter and how to lookup type information fromSecretDocument
s when reading them. Uses aDefaultVaultTypeMapper
by default. Setting this to null will reset theTypeMapper
to the default one.- Parameters:
typeMapper
- the typeMapper to set, must not be null.
-
getMappingContext
public MappingContext<? extends VaultPersistentEntity<?>,VaultPersistentProperty> getMappingContext() -
read
-
readMap
- Parameters:
type
- theMap
TypeInformation
to be used to unmarshal thisMap
.sourceMap
- must not be null- Returns:
- the converted
Map
.
-
write
-
writeInternal
protected void writeInternal(Object obj, org.springframework.vault.repository.convert.SecretDocumentAccessor sink, @Nullable TypeInformation<?> typeHint) Internal write conversion method which should be used for nested invocations.- Parameters:
obj
-sink
-typeHint
-
-
writeInternal
protected void writeInternal(Object obj, org.springframework.vault.repository.convert.SecretDocumentAccessor sink, VaultPersistentEntity<?> entity) -
writePropertyInternal
protected void writePropertyInternal(@Nullable Object obj, org.springframework.vault.repository.convert.SecretDocumentAccessor accessor, VaultPersistentProperty prop) -
createCollection
Writes the givenCollection
using the givenVaultPersistentProperty
information.- Parameters:
collection
- must not be null.property
- must not be null.- Returns:
- the converted
List
.
-
createMap
Writes the givenMap
using the givenVaultPersistentProperty
information.- Parameters:
map
- must not null.property
- must not be null.- Returns:
- the converted
Map
.
-
writeMapInternal
protected Map<String,Object> writeMapInternal(Map<Object, Object> obj, Map<String, Object> bson, TypeInformation<?> propertyType) - Parameters:
obj
- must not be null.bson
- must not be null.propertyType
- must not be null.- Returns:
- the converted
Map
.
-
addCustomTypeKeyIfNecessary
protected void addCustomTypeKeyIfNecessary(@Nullable TypeInformation<?> type, Object value, org.springframework.vault.repository.convert.SecretDocumentAccessor accessor) Adds custom type information to the givenSecretDocument
if necessary. That is if the value is not the same as the one given. This is usually the case if you store a subtype of the actual declared type of the property.- Parameters:
type
- type hint.value
- must not be null.accessor
- must not be null.
-