Package dev.morphia

Interface ObjectFactory


  • public interface ObjectFactory
    The ObjectFactory is used by morphia to create instances of classes which can be customized to fit a particular applications needs.
    • Method Detail

      • createInstance

        <T> T createInstance​(Class<T> clazz)
        Creates an instance of the given class.
        Type Parameters:
        T - the type of the entity
        Parameters:
        clazz - type class to instantiate
        Returns:
        the new instance
      • createInstance

        <T> T createInstance​(Class<T> clazz,
                             org.bson.Document document)
        Creates an instance of the class defined in the discriminator field in the document passed in. If that field is missing, the given Class is used instead.
        Type Parameters:
        T - the type of the entity
        Parameters:
        clazz - type class to instantiate
        document - the state to populate the new instance with
        Returns:
        the new instance
      • createInstance

        Object createInstance​(Mapper mapper,
                              PropertyModel mf,
                              org.bson.Document document)
        Creates an instance of the class defined in the discriminator field in the document passed in. If that field is missing, morphia attempts to the MappedField to determine which concrete class to instantiate.
        Parameters:
        mapper - the Mapper to use
        mf - the MappedField to consult when creating the instance
        document - the state to populate the new instance with
        Returns:
        the new instance
      • createList

        List createList​(PropertyModel mf)
        Defines how morphia creates a List object.
        Parameters:
        mf - the MappedField containing any metadata that might define the type of the List to create
        Returns:
        the List
      • createMap

        Map createMap​(PropertyModel mf)
        Defines how morphia creates a Map object.
        Parameters:
        mf - the MappedField containing any metadata that might define the type of the Map to create
        Returns:
        the Map
      • createSet

        Set createSet​(PropertyModel mf)
        Defines how morphia creates a Set object.
        Parameters:
        mf - the MappedField containing any metadata that might define the type of the Set to create
        Returns:
        the Set