Interface MongoConverter

All Superinterfaces:
CodecRegistryProvider, org.springframework.data.convert.EntityConverter<MongoPersistentEntity<?>,MongoPersistentProperty,Object,org.bson.conversions.Bson>, org.springframework.data.convert.EntityReader<Object,org.bson.conversions.Bson>, org.springframework.data.convert.EntityWriter<Object,org.bson.conversions.Bson>, MongoWriter<Object>
All Known Implementing Classes:
AbstractMongoConverter, MappingMongoConverter

public interface MongoConverter extends org.springframework.data.convert.EntityConverter<MongoPersistentEntity<?>,MongoPersistentProperty,Object,org.bson.conversions.Bson>, MongoWriter<Object>, org.springframework.data.convert.EntityReader<Object,org.bson.conversions.Bson>, CodecRegistryProvider
Central Mongo specific converter interface which combines MongoWriter and EntityReader.
Author:
Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch, Ryan Gibb
  • Method Summary

    Modifier and Type
    Method
    Description
    default Object
    convertId(Object id, Class<?> targetType)
    Converts the given raw id value into either ObjectId or String.
    default org.bson.codecs.configuration.CodecRegistry
    Get the underlying CodecRegistry used by the MongoDB Java driver.
    org.springframework.data.convert.CustomConversions
    Returns the CustomConversions for this converter.
    org.springframework.data.projection.ProjectionFactory
    Returns the ProjectionFactory for this converter.
    Returns the TypeMapper being used to write type information into Documents created with that converter.
    default <S, T> T
    mapValueToTargetType(S source, Class<T> targetType, DbRefResolver dbRefResolver)
    Mapping function capable of converting values into a desired target type by eg. extracting the actual java type from a given BsonValue.
    <R> R
    project(org.springframework.data.projection.EntityProjection<R,?> descriptor, org.bson.conversions.Bson bson)
    Apply a projection to Bson and return the projection return type R.

    Methods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider

    getCodecFor, hasCodecFor

    Methods inherited from interface org.springframework.data.convert.EntityConverter

    getConversionService, getMappingContext

    Methods inherited from interface org.springframework.data.convert.EntityReader

    read

    Methods inherited from interface org.springframework.data.convert.EntityWriter

    write

    Methods inherited from interface org.springframework.data.mongodb.core.convert.MongoWriter

    convertToMongoType, convertToMongoType, convertToMongoType, toDBRef, toDocumentPointer
  • Method Details

    • getTypeMapper

      MongoTypeMapper getTypeMapper()
      Returns the TypeMapper being used to write type information into Documents created with that converter.
      Returns:
      will never be null.
    • getProjectionFactory

      org.springframework.data.projection.ProjectionFactory getProjectionFactory()
      Returns the ProjectionFactory for this converter.
      Returns:
      will never be null.
      Since:
      3.4
    • getCustomConversions

      org.springframework.data.convert.CustomConversions getCustomConversions()
      Returns the CustomConversions for this converter.
      Returns:
      will never be null.
      Since:
      3.4
    • project

      <R> R project(org.springframework.data.projection.EntityProjection<R,?> descriptor, org.bson.conversions.Bson bson)
      Apply a projection to Bson and return the projection return type R. Non-projecting descriptors fall back to regular object materialization.
      Type Parameters:
      R -
      Parameters:
      descriptor - the projection descriptor, must not be null.
      bson - must not be null.
      Returns:
      a new instance of the projection return type R.
      Since:
      3.4
    • mapValueToTargetType

      @Nullable default <S, T> T mapValueToTargetType(S source, Class<T> targetType, DbRefResolver dbRefResolver)
      Mapping function capable of converting values into a desired target type by eg. extracting the actual java type from a given BsonValue.
      Type Parameters:
      S -
      T -
      Parameters:
      targetType - must not be null.
      dbRefResolver - must not be null.
      Returns:
      new typed Function.
      Throws:
      IllegalArgumentException - if targetType is null.
      Since:
      2.1
    • convertId

      @Nullable default Object convertId(@Nullable Object id, Class<?> targetType)
      Converts the given raw id value into either ObjectId or String.
      Parameters:
      id - can be null.
      targetType - must not be null.
      Returns:
      null if source id is already null.
      Since:
      2.2
    • getCodecRegistry

      default org.bson.codecs.configuration.CodecRegistry getCodecRegistry()
      Description copied from interface: CodecRegistryProvider
      Get the underlying CodecRegistry used by the MongoDB Java driver.
      Specified by:
      getCodecRegistry in interface CodecRegistryProvider
      Returns:
      never null.