你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

MappingCosmosConverter Class

  • java.lang.Object
    • com.azure.spring.data.cosmos.core.convert.MappingCosmosConverter

Implements

org.springframework.context.ApplicationContextAware org.springframework.data.convert.EntityConverter<CosmosPersistentEntity<?>,CosmosPersistentProperty,Object,com.fasterxml.jackson.databind.JsonNode>

public class MappingCosmosConverter
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 Type Field and Description
protected org.springframework.core.convert.support.GenericConversionService conversionService

Generic conversion service

protected final org.springframework.data.mapping.context.MappingContext<<?>,CosmosPersistentProperty> mappingContext

Mapping context

Constructor Summary

Constructor Description
MappingCosmosConverter(MappingContext<? extends CosmosPersistentEntity<?>,CosmosPersistentProperty> mappingContext, ObjectMapper objectMapper)

Initialization

Method Summary

Modifier and Type Method and Description
R read(Class<R> type, JsonNode jsonNode)
List<String> getTransientFields(T objectToSave, CosmosEntityInformation<T,?> entityInfo)

To get transient fields

Map<Field,Object> getTransientFieldsMap(T object, List<String> transientFields)

To get transient fields and their values

com.fasterxml.jackson.databind.JsonNode repopulateTransientFields(JsonNode responseItem, Map<Field,Object> transientValues)

To repopulate any transient fields that were stripped from the original object

com.fasterxml.jackson.databind.JsonNode writeJsonNode(Object sourceEntity, List<String> transientFields)

To write source entity as a cosmos item

org.springframework.context.ApplicationContext getApplicationContext()

To get application context

org.springframework.core.convert.ConversionService getConversionService()
org.springframework.data.mapping.context.MappingContext<<?>,CosmosPersistentProperty> getMappingContext()

To get mapping context

void setApplicationContext(ApplicationContext applicationContext)
static Object toCosmosDbValue(Object fromPropertyValue)

Convert a property value to the value stored in CosmosDB

void write(Object source, JsonNode sink)
com.fasterxml.jackson.databind.JsonNode writeJsonNode(Object sourceEntity)

To write source entity as a cosmos item

Methods inherited from java.lang.Object

Field Details

conversionService

protected GenericConversionService conversionService

Generic conversion service

mappingContext

protected final MappingContext,CosmosPersistentProperty> mappingContext

Mapping context

Constructor Details

MappingCosmosConverter

public MappingCosmosConverter(MappingContext,CosmosPersistentProperty> mappingContext, ObjectMapper objectMapper)

Initialization

Parameters:

mappingContext - must not be null
objectMapper - must not be null

Method Details

read

public R read(Class type, JsonNode jsonNode)

Parameters:

type
jsonNode

getTransientFields

public List getTransientFields(T objectToSave, CosmosEntityInformation entityInfo)

To get transient fields

Parameters:

objectToSave - must not be null
entityInfo - entity information

Returns:

List

getTransientFieldsMap

public Map getTransientFieldsMap(T object, List transientFields)

To get transient fields and their values

Parameters:

object - must not be null
transientFields - transient fields

Returns:

HashMap

repopulateTransientFields

public JsonNode repopulateTransientFields(JsonNode responseItem, Map transientValues)

To repopulate any transient fields that were stripped from the original object

Parameters:

responseItem - must not be null
transientValues - transient fields and their values

Returns:

CosmosItemProperties

writeJsonNode

public JsonNode writeJsonNode(Object sourceEntity, List transientFields)

To write source entity as a cosmos item

Parameters:

sourceEntity - must not be null
transientFields - transient fields

Returns:

CosmosItemProperties

getApplicationContext

public ApplicationContext getApplicationContext()

To get application context

Returns:

ApplicationContext

getConversionService

public ConversionService getConversionService()

getMappingContext

public MappingContext,CosmosPersistentProperty> getMappingContext()

To get mapping context

Returns:

MappingContext

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)

Parameters:

applicationContext

toCosmosDbValue

public static Object toCosmosDbValue(Object fromPropertyValue)

Convert a property value to the value stored in CosmosDB

Parameters:

fromPropertyValue - source property value

Returns:

fromPropertyValue converted property value stored in CosmosDB

write

public void write(Object source, JsonNode sink)

Parameters:

source
sink

writeJsonNode

public JsonNode writeJsonNode(Object sourceEntity)

To write source entity as a cosmos item

Parameters:

sourceEntity - must not be null

Returns:

CosmosItemProperties

Applies to