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 Details

    • mappingContext

      protected final org.springframework.data.mapping.context.MappingContext<? extends CosmosPersistentEntity<?>,CosmosPersistentProperty> mappingContext
      Mapping context
    • conversionService

      protected org.springframework.core.convert.support.GenericConversionService conversionService
      Generic 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 null
      objectMapper - must not be null
  • Method Details

    • read

      public <R> R read(Class<R> type, com.fasterxml.jackson.databind.JsonNode jsonNode)
      Specified by:
      read in interface org.springframework.data.convert.EntityReader<Object,com.fasterxml.jackson.databind.JsonNode>
    • write

      public void write(Object source, com.fasterxml.jackson.databind.JsonNode sink)
      Specified by:
      write in interface org.springframework.data.convert.EntityWriter<Object,com.fasterxml.jackson.databind.JsonNode>
    • writeJsonNode

      public com.fasterxml.jackson.databind.JsonNode writeJsonNode(Object sourceEntity)
      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 type
      CosmosAccessException - 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 interface org.springframework.context.ApplicationContextAware
    • getConversionService

      public org.springframework.core.convert.ConversionService getConversionService()
      Specified by:
      getConversionService in interface org.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 interface org.springframework.data.convert.EntityConverter<CosmosPersistentEntity<?>,CosmosPersistentProperty,Object,com.fasterxml.jackson.databind.JsonNode>
      Returns:
      MappingContext
    • 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