Skip to content

[cpp-rest-sdk-client] handling datetime type #12247

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public:
static web::json::value toJson( const std::shared_ptr<HttpContent>& val );
template<typename T>
static web::json::value toJson( const std::shared_ptr<T>& val );
static web::json::value toJson( const std::shared_ptr<utility::datetime>& val );
template<typename T>
static web::json::value toJson( const std::vector<T>& val );
template<typename T>
Expand All @@ -80,6 +81,7 @@ public:
static bool fromString( const utility::string_t& val, std::shared_ptr<HttpContent> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::shared_ptr<T>& );
static bool fromString( const utility::string_t& val, std::shared_ptr<utility::datetime>& outVal );
template<typename T>
static bool fromString( const utility::string_t& val, std::vector<T> & );
template<typename T>
Expand All @@ -96,6 +98,7 @@ public:
static bool fromJson( const web::json::value& val, std::shared_ptr<HttpContent> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::shared_ptr<T>& );
static bool fromJson( const web::json::value& val, std::shared_ptr<utility::datetime> &outVal );
template<typename T>
static bool fromJson( const web::json::value& val, std::vector<T> & );
template<typename T>
Expand All @@ -113,6 +116,7 @@ public:
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<T>& , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
static std::shared_ptr<HttpContent> toHttpContent(const utility::string_t& name, const std::shared_ptr<utility::datetime>& value , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ web::json::value ModelBase::toJson( const std::shared_ptr<HttpContent>& content
}
return value;
}
web::json::value ModelBase::toJson( const std::shared_ptr<utility::datetime>& val )
{
web::json::value retVal;
if(val != nullptr)
{
retVal = toJson(*val);
}
return retVal;
}
bool ModelBase::fromString( const utility::string_t& val, bool &outVal )
{
utility::stringstream_t ss(val);
Expand Down Expand Up @@ -242,6 +251,19 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<HttpCo
}
return ok;
}
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<utility::datetime>& outVal )
{
bool ok = false;
if(outVal == nullptr)
{
outVal = std::shared_ptr<utility::datetime>(new utility::datetime());
}
if( outVal != nullptr )
{
ok = fromJson(web::json::value::parse(val), *outVal);
}
return ok;
}
bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
{
outVal = !val.is_boolean() ? false : val.as_bool();
Expand Down Expand Up @@ -319,6 +341,19 @@ bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpConte
}
return result;
}
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<utility::datetime> &outVal )
{
bool ok = false;
if(outVal == nullptr)
{
outVal = std::shared_ptr<utility::datetime>(new utility::datetime());
}
if( outVal != nullptr )
{
ok = fromJson(val, *outVal);
}
return ok;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
Expand Down Expand Up @@ -414,6 +449,18 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
}
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr<utility::datetime>& value , const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
if (value != nullptr )
{
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string( toJson(*value).serialize() ) ) ) );
}
return content;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, bool & outVal )
{
utility::string_t str;
Expand Down