com.holonplatform.datastore.mongo.core.document

## Interface DocumentConverter<R>

- Type Parameters:
    `R` - Conversion result type

      public interface DocumentConverter<R>

  Converter to convert a `Document` instance into a different type.
  Since:
    5.2.0

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> DocumentConverter<T>` | `bean(com.holonplatform.core.beans.BeanPropertySet<T> beanPropertySet)` Create a new `DocumentConverter` to convert documents into Java Bean instances.
    `static <T> DocumentConverter<T>` | `bean(Class<T> beanClass)` Create a new `DocumentConverter` to convert documents into Java Bean instances.
    `R` | `convert(MongoResolutionContext<?> context, org.bson.Document document)` Convert a `Document` into expected result type.
    `static <R> DocumentConverter<R>` | `create(Class<R> type, BiFunction<MongoResolutionContext<?>,org.bson.Document,R> converter)` Create a new `DocumentConverter`.
    `static <T> DocumentConverter<T>` | `expression(com.holonplatform.core.TypedExpression<T> expression, String selection)` Create a new `DocumentConverter` to convert a document field using given expression.
    `Class<? extends R>` | `getConversionType()` Get the type into which this converter is able to convert a `Document`.
    `static DocumentConverter<org.bson.Document>` | `identity()` Get a `DocumentConverter` which simply returns the document instance, without performing any conversion operation.
    `static <P extends com.holonplatform.core.property.Property> DocumentConverter<com.holonplatform.core.property.PropertyBox>` | `propertyBox(Iterable<P> properties)` Create a new `DocumentConverter` to convert documents into `PropertyBox` instances using given property set.
    `static <P extends com.holonplatform.core.property.Property> DocumentConverter<com.holonplatform.core.property.PropertyBox>` | `propertyBox(P... properties)` Create a new `DocumentConverter` to convert documents into `PropertyBox` instances using given property set.
    `static <T> DocumentConverter<T>` | `value(Class<T> valueType, String selection)` Create a new `DocumentConverter` to return a document field without performing any conversion.

- - ### Method Detail

    - #### getConversionType

          Class<? extends R> getConversionType()

      Get the type into which this converter is able to convert a `Document`.
      Returns:
        The conversion type

    - #### convert

          R convert(MongoResolutionContext<?> context,
                    org.bson.Document document)

      Convert a `Document` into expected result type.
      Parameters:
        `context` - Resolution context
        `document` - The Document to convert
      Returns:
        Converted result

    - #### create

          static <R> DocumentConverter<R> create(Class<R> type,
                                                 BiFunction<MongoResolutionContext<?>,org.bson.Document,R> converter)

      Create a new `DocumentConverter`.
      Type Parameters:
        `R` - Conversion type
      Parameters:
        `type` - Conversion type (not null)
        `converter` - Conversion function (not null)
      Returns:
        A new `DocumentConverter` instance

    - #### propertyBox

          static <P extends com.holonplatform.core.property.Property> DocumentConverter<com.holonplatform.core.property.PropertyBox> propertyBox(Iterable<P> properties)

      Create a new `DocumentConverter` to convert documents into `PropertyBox` instances using given property set.
      Type Parameters:
        `P` - Property type
      Parameters:
        `properties` - The property set to use (not null)
      Returns:
        A new `PropertyBox` type `DocumentConverter`

    - #### propertyBox

          static <P extends com.holonplatform.core.property.Property> DocumentConverter<com.holonplatform.core.property.PropertyBox> propertyBox(P... properties)

      Create a new `DocumentConverter` to convert documents into `PropertyBox` instances using given property set.
      Type Parameters:
        `P` - Property type
      Parameters:
        `properties` - The property set to use (not null)
      Returns:
        A new `PropertyBox` type `DocumentConverter`

    - #### bean

          static <T> DocumentConverter<T> bean(Class<T> beanClass)

      Create a new `DocumentConverter` to convert documents into Java Bean instances.
      Type Parameters:
        `T` - Bean class
      Parameters:
        `beanClass` - Bean class to use (not null)
      Returns:
        A new bean `DocumentConverter`

    - #### bean

          static <T> DocumentConverter<T> bean(com.holonplatform.core.beans.BeanPropertySet<T> beanPropertySet)

      Create a new `DocumentConverter` to convert documents into Java Bean instances.
      Type Parameters:
        `T` - Bean class
      Parameters:
        `beanPropertySet` - Bean property set to use (not null)
      Returns:
        A new bean `DocumentConverter`

    - #### expression

          static <T> DocumentConverter<T> expression(com.holonplatform.core.TypedExpression<T> expression,
                                                     String selection)

      Create a new `DocumentConverter` to convert a document field using given expression.
      Type Parameters:
        `T` - Expression type
      Parameters:
        `expression` - Field expression
        `selection` - Field name
      Returns:
        A new expression `DocumentConverter`

    - #### value

          static <T> DocumentConverter<T> value(Class<T> valueType,
                                                String selection)

      Create a new `DocumentConverter` to return a document field without performing any conversion.
      Type Parameters:
        `T` - Value type
      Parameters:
        `valueType` - Value type
        `selection` - Field name
      Returns:
        A new value `DocumentConverter`

    - #### identity

          static DocumentConverter<org.bson.Document> identity()

      Get a `DocumentConverter` which simply returns the document instance, without performing any conversion operation.
      Returns:
        A new identity document converter

Copyright © 2019 The Holon Platform. All rights reserved.