/**
   * Converts the argument(s) to the target type (specified by {@code MappedFieldPath}) and then to
   * a Mongo object.
   *
   * @param arguments Single or multiple arguments in a list.
   * @param mfp The mapped field path.
   * @param singleValue Whether a single argument is expected.
   * @return An argument(s) converted to Mongo value.
   * @throws cz.jirutka.rsql.mongodb.morphia.RSQLArgumentFormatException
   */
  protected Object convertToMappedValue(
      List<String> arguments, MappedFieldPath mfp, boolean singleValue) {

    Object value =
        singleValue
            ? converter.convert(arguments.get(0), mfp.getTargetValueType())
            : converter.convert(arguments, mfp.getTargetValueType());

    return mapper.toMongoObject(mfp.getMappedField(), null, value);
  }