public static Object unwrapBsonable(Object value) {
    if (value instanceof Document) {
      for (Entry<String, Object> entry : ((Document) value).entrySet()) {
        entry.setValue(unwrapBsonable(entry.getValue()));
      }
      return value;
    }

    if (value instanceof Iterable<?>) {
      return ImmutableList.copyOf(unwrapBsonableIterable((Iterable<?>) value));
    }

    if (value instanceof Constraints.ConstraintHost) {
      return convertToBson((Constraints.ConstraintHost) value);
    }

    if (value == null
        || value instanceof Number
        || value instanceof Boolean
        || value instanceof String) {
      return value;
    }

    if (value instanceof Adapted<?>) {
      return ((Adapted<?>) value).toBson();
    }

    return String.valueOf(value);
  }
Builds bson with index definition. The difference with
{@link #convertToBson(Constraints.ConstraintHost)} is that this method fails on duplicate
fields. Currently only one index is allowed per field.
@see <a href="https://docs.mongodb.com/manual/indexes/">Mongo Indexes</a>
mongo/src/org/immutables/mongo/repository/internal/Support.java