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
ConstructorsConstructorDescriptionMappingVaultConverter(MappingContext<? extends VaultPersistentEntity<?>, VaultPersistentProperty> mappingContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCustomTypeKeyIfNecessary(@Nullable TypeInformation<?> type, Object value, SecretDocumentAccessor accessor) Adds custom type information to the givenSecretDocumentif necessary.createCollection(Collection<?> collection, VaultPersistentProperty property) Writes the givenCollectionusing the givenVaultPersistentPropertyinformation.createMap(Map<Object, Object> map, VaultPersistentProperty property) Writes the givenMapusing the givenVaultPersistentPropertyinformation.MappingContext<? extends VaultPersistentEntity<?>,VaultPersistentProperty> <S> Sread(Class<S> type, SecretDocument source) readMap(TypeInformation<?> type, Map<String, Object> sourceMap) voidsetTypeMapper(VaultTypeMapper typeMapper) Configures theVaultTypeMapperto be used to add type information toSecretDocuments created by the converter and how to lookup type information fromSecretDocuments when reading them.voidwrite(Object source, SecretDocument sink) protected voidwriteInternal(Object obj, SecretDocumentAccessor sink, @Nullable TypeInformation<?> typeHint) Internal write conversion method which should be used for nested invocations.protected voidwriteInternal(Object obj, SecretDocumentAccessor sink, VaultPersistentEntity<?> entity) writeMapInternal(Map<Object, Object> obj, Map<String, Object> bson, TypeInformation<?> propertyType) protected voidwritePropertyInternal(@Nullable Object obj, 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 theVaultTypeMapperto be used to add type information toSecretDocuments created by the converter and how to lookup type information fromSecretDocuments when reading them. Uses aDefaultVaultTypeMapperby default. Setting this to null will reset theTypeMapperto the default one.- Parameters:
typeMapper- the typeMapper to set, must not be null.
-
getMappingContext
public MappingContext<? extends VaultPersistentEntity<?>,VaultPersistentProperty> getMappingContext() -
read
-
readMap
protected Map<@Nullable Object,@Nullable Object> readMap(TypeInformation<?> type, Map<String, Object> sourceMap) - Parameters:
type- theMapTypeInformationto be used to unmarshal thisMap.sourceMap- must not be null- Returns:
- the converted
Map.
-
write
-
writeInternal
protected void writeInternal(Object obj, 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, SecretDocumentAccessor sink, VaultPersistentEntity<?> entity) -
writePropertyInternal
protected void writePropertyInternal(@Nullable Object obj, SecretDocumentAccessor accessor, VaultPersistentProperty prop) -
createCollection
Writes the givenCollectionusing the givenVaultPersistentPropertyinformation.- Parameters:
collection- must not be null.property- must not be null.- Returns:
- the converted
List.
-
createMap
Writes the givenMapusing the givenVaultPersistentPropertyinformation.- 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, SecretDocumentAccessor accessor) Adds custom type information to the givenSecretDocumentif 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.
-