Class MappingCosmosConverter
java.lang.Object
com.azure.spring.data.cosmos.core.convert.MappingCosmosConverter
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.data.convert.EntityConverter<CosmosPersistentEntity<?>,
,CosmosPersistentProperty, Object, com.fasterxml.jackson.databind.JsonNode> org.springframework.data.convert.EntityReader<Object,
,com.fasterxml.jackson.databind.JsonNode> org.springframework.data.convert.EntityWriter<Object,
com.fasterxml.jackson.databind.JsonNode>
public class MappingCosmosConverter
extends Object
implements org.springframework.data.convert.EntityConverter<CosmosPersistentEntity<?>,CosmosPersistentProperty,Object,com.fasterxml.jackson.databind.JsonNode>, org.springframework.context.ApplicationContextAware
A converter class between common types and cosmosItemProperties
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.springframework.core.convert.support.GenericConversionService
Generic conversion serviceprotected final org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>,
CosmosPersistentProperty> Mapping context -
Constructor Summary
ConstructorDescriptionMappingCosmosConverter
(org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>, CosmosPersistentProperty> mappingContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Initialization -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.context.ApplicationContext
To get application contextorg.springframework.core.convert.ConversionService
org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>,
CosmosPersistentProperty> To get mapping context<R> R
void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) static Object
toCosmosDbValue
(Object fromPropertyValue) Convert a property value to the value stored in CosmosDBvoid
com.fasterxml.jackson.databind.JsonNode
writeJsonNode
(Object sourceEntity) To write source entity as a cosmos item
-
Field Details
-
mappingContext
protected final org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>,CosmosPersistentProperty> mappingContextMapping context -
conversionService
protected org.springframework.core.convert.support.GenericConversionService conversionServiceGeneric conversion service
-
-
Constructor Details
-
MappingCosmosConverter
public MappingCosmosConverter(org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>, CosmosPersistentProperty> mappingContext, @Qualifier("cosmosObjectMapper") com.fasterxml.jackson.databind.ObjectMapper objectMapper) Initialization- Parameters:
mappingContext
- must not be nullobjectMapper
- must not be null
-
-
Method Details
-
read
- Specified by:
read
in interfaceorg.springframework.data.convert.EntityReader<Object,
com.fasterxml.jackson.databind.JsonNode>
-
write
- Specified by:
write
in interfaceorg.springframework.data.convert.EntityWriter<Object,
com.fasterxml.jackson.databind.JsonNode>
-
writeJsonNode
To write source entity as a cosmos item- Parameters:
sourceEntity
- must not be null- Returns:
- CosmosItemProperties
- Throws:
org.springframework.data.mapping.MappingException
- no mapping metadata for entity typeCosmosAccessException
- fail to map document value
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()To get application context- Returns:
- ApplicationContext
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
-
getConversionService
public org.springframework.core.convert.ConversionService getConversionService()- Specified by:
getConversionService
in interfaceorg.springframework.data.convert.EntityConverter<CosmosPersistentEntity<?>,
CosmosPersistentProperty, Object, com.fasterxml.jackson.databind.JsonNode>
-
getMappingContext
public org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>,CosmosPersistentProperty> getMappingContext()To get mapping context- Specified by:
getMappingContext
in interfaceorg.springframework.data.convert.EntityConverter<CosmosPersistentEntity<?>,
CosmosPersistentProperty, Object, com.fasterxml.jackson.databind.JsonNode> - Returns:
- MappingContext
-
toCosmosDbValue
Convert a property value to the value stored in CosmosDB- Parameters:
fromPropertyValue
- source property value- Returns:
- fromPropertyValue converted property value stored in CosmosDB
-