Repository: oatpp/oatpp
File: src/oatpp/parser/json/mapping/Deserializer.hpp (C++)

Code before:
    bool allowUnknownFields = true;

  };

public:
  typedef oatpp::Void (*DeserializerMethod)(Deserializer*, parser::Caret&, const Type* const);
private:
  static void skipScope(oatpp::parser::Caret& caret, v_char8 charOpen, v_char8 charClose);
  static void skipString(oatpp::parser::Caret& caret);
  static void skipToken(oatpp::parser::Caret& caret);
  static void skipValue(oatpp::parser::Caret& caret);
private:
  static const Type* guessNumberType(oatpp::parser::Caret& caret);
  static const Type* guessType(oatpp::parser::Caret& caret);
private:

  template<class T>
  static oatpp::Void deserializeInt(Deserializer* deserializer, parser::Caret& caret, const Type* const type){

    (void) deserializer;
    (void) type;

    if(caret.isAtText("null", true)){
      return oatpp::Void(T::Class::getType());
    } else {
      //TODO: the below gives warning C4244: 'argument': conversion from 'v_int64' to 'TValueType', possible loss of data
      return T(caret.parseInt());
    }

  }

  template<class T>
  static oatpp::Void deserializeUInt(Deserializer* deserializer, parser::Caret& caret, const Type* const type){

    (void) deserializer;
    (void) type;

    if(caret.isAtText("null", true)){
      return oatpp::Void(T::Class::getType());
    } else {
      //TODO: the below gives warning C4244: 'argument': conversion from 'v_uint64' to 'TValueType', possible loss of data
      return T(caret.parseUnsignedInt());
    }

  }

  template<class Collection>
  static oatpp::Void deserializeList(Deserializer* deserializer, parser::Caret& caret, const Type* const type) {

    if(caret.isAtText("null", true)){
      return oatpp::Void(type);

Review comment (suggestion):
Example of data loss here:

```cpp
oatpp::String json = "256";
auto value = jsonObjectMapper->readFromString<oatpp::UInt8>(json); // UInt8 will be rounded to 0
```

The question is - do we care about such cases?

I think for now - we can just static cast the value to silent the error, and leave the corresponding `TODO info here`

Code after:
    bool allowUnknownFields = true;

  };

public:
  typedef oatpp::Void (*DeserializerMethod)(Deserializer*, parser::Caret&, const Type* const);
private:
  static void skipScope(oatpp::parser::Caret& caret, v_char8 charOpen, v_char8 charClose);
  static void skipString(oatpp::parser::Caret& caret);
  static void skipToken(oatpp::parser::Caret& caret);
  static void skipValue(oatpp::parser::Caret& caret);
private:
  static const Type* guessNumberType(oatpp::parser::Caret& caret);
  static const Type* guessType(oatpp::parser::Caret& caret);
private:

  template<class T>
  static oatpp::Void deserializeInt(Deserializer* deserializer, parser::Caret& caret, const Type* const type){

    (void) deserializer;
    (void) type;

    if(caret.isAtText("null", true)){
      return oatpp::Void(T::Class::getType());
    } else {
      //TODO: shall we handle overflow cases like
      // oatpp::String json = "128";
      // auto value = jsonObjectMapper->readFromString<oatpp::Int8>(json); // UInt8 will overflow to -128
      return T(static_cast<typename T::UnderlyingType>(caret.parseInt()));
    }

  }

  template<class T>
  static oatpp::Void deserializeUInt(Deserializer* deserializer, parser::Caret& caret, const Type* const type){

    (void) deserializer;
    (void) type;

    if(caret.isAtText("null", true)){
      return oatpp::Void(T::Class::getType());
    } else {
      //TODO: shall we handle overflow cases like
      // oatpp::String json = "256";
      // auto value = jsonObjectMapper->readFromString<oatpp::UInt8>(json); // UInt8 will overflow to 0
      return T(static_cast<typename T::UnderlyingType>(caret.parseUnsignedInt()));
    }

  }

  template<class Collection>