org.springframework.data.mongodb.core.convert

Interface MongoWriter<T>

  • Type Parameters:
    T - the type of the object to convert to a Document
    All Superinterfaces:
    EntityWriter<T,org.bson.conversions.Bson>
    All Known Subinterfaces:
    MongoConverter
    All Known Implementing Classes:
    AbstractMongoConverter, MappingMongoConverter


    public interface MongoWriter<T>
    extends EntityWriter<T,org.bson.conversions.Bson>
    A MongoWriter is responsible for converting an object of type T to the native MongoDB representation Document.
    Author:
    Mark Pollack, Thomas Risberg, Oliver Gierke, Christoph Strobl
    • Method Detail

      • convertToMongoType

        @Nullable
        default Object convertToMongoType(@Nullable
                                                    Object obj)
        Converts the given object into one Mongo will be able to store natively. If the given object can already be stored as is, no conversion will happen.
        Parameters:
        obj - can be null.
        Returns:
      • convertToMongoType

        @Nullable
        Object convertToMongoType(@Nullable
                                            Object obj,
                                            @Nullable
                                            TypeInformation<?> typeInformation)
        Converts the given object into one Mongo will be able to store natively but retains the type information in case the given TypeInformation differs from the given object type.
        Parameters:
        obj - can be null.
        typeInformation - can be null.
        Returns:
      • toDBRef

        com.mongodb.DBRef toDBRef(Object object,
                                  @Nullable
                                  MongoPersistentProperty referingProperty)
        Creates a DBRef to refer to the given object.
        Parameters:
        object - the object to create a DBRef to link to. The object's type has to carry an id attribute.
        referingProperty - the client-side property referring to the object which might carry additional metadata for the DBRef object to create. Can be null.
        Returns:
        will never be null.