Repository: oatpp/oatpp
File: src/oatpp/web/server/api/ApiController.hpp (C++)

Code before:
      success = false;
      OATPP_LOGE("[oatpp::web::server::api::ApiController::TypeInterpretation::fromString()]",
                 "Error. No conversion from '%s' to '%s' is defined.", "oatpp::String", typeName->getData());
      throw std::runtime_error("[oatpp::web::server::api::ApiController::TypeInterpretation::fromString()]: Error. "
                               "No conversion from 'oatpp::String' to '" + typeName->std_str() + "' is defined. "
                               "Please define type conversion.");
    }

  };

};

template<>
struct ApiController::TypeInterpretation <oatpp::String> {
  static oatpp::String fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    success = true;
    return text;
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::Int8> {
  static oatpp::Int8 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    //TODO: the below gives warning C4244: 'argument': conversion from 'v_int32' to 'TValueType', possible loss of data
    return utils::conversion::strToInt32(text, success);
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::UInt8> {
  static oatpp::UInt8 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    //TODO: the below gives 'argument': conversion from 'v_uint32' to 'TValueType', possible loss of data
    return utils::conversion::strToUInt32(text, success);
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::Int16> {
  static oatpp::Int16 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    //TODO: the below gives warning C4244: 'argument': conversion from 'v_int32' to 'TValueType', possible loss of data
    return utils::conversion::strToInt32(text, success);
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::UInt16> {
  static oatpp::UInt16 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {

Review comment (suggestion):
This is the same case as in the JSON deserializer.
We could probably check that the value actually falls in the range of `Int8`, but it's out-of-scope for now.

Let's just static cast it to silent the error, and leave the corresponding `TODO`

Code after:
      success = false;
      OATPP_LOGE("[oatpp::web::server::api::ApiController::TypeInterpretation::fromString()]",
                 "Error. No conversion from '%s' to '%s' is defined.", "oatpp::String", typeName->getData());
      throw std::runtime_error("[oatpp::web::server::api::ApiController::TypeInterpretation::fromString()]: Error. "
                               "No conversion from 'oatpp::String' to '" + typeName->std_str() + "' is defined. "
                               "Please define type conversion.");
    }

  };

};

template<>
struct ApiController::TypeInterpretation <oatpp::String> {
  static oatpp::String fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    success = true;
    return text;
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::Int8> {
  static oatpp::Int8 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    //TODO: check the range and perhaps throw an exception if the variable doesn't fit
    return static_cast<Int8::UnderlyingType>(utils::conversion::strToInt32(text, success));
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::UInt8> {
  static oatpp::UInt8 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    //TODO: check the range and perhaps throw an exception if the variable doesn't fit
    return static_cast<UInt8::UnderlyingType>(utils::conversion::strToUInt32(text, success));
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::Int16> {
  static oatpp::Int16 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {
    (void) typeName;
    //TODO: check the range and perhaps throw an exception if the variable doesn't fit
    return static_cast<Int16::UnderlyingType>(utils::conversion::strToInt32(text, success));
  }
};

template<>
struct ApiController::TypeInterpretation <oatpp::UInt16> {
  static oatpp::UInt16 fromString(const oatpp::String& typeName, const oatpp::String& text, bool& success) {