Rest API出现restc-cpp后数据断言错误



我正试图用restc-cpp库在C++中发布json数据,但我遇到了以下错误:

Assertion failed: false, file librestc-cppincluderestc-cpp/SerializeJson.h, line 1273

我已经按照这个页面上的例子将数据发布到服务器

struct Post
{
int i;
};

// The C++ main function - the place where any adventure starts
int main() {
Post post;
post.i = 22;
// Create an instance of the rest client
auto rest_client = RestClient::Create();
// Create and instantiate a Post from data received from the server.
auto done = rest_client->ProcessWithPromise([&](Context& ctx)
{
// This is a co-routine, running in a worker-thread

auto reply = RequestBuilder(ctx)
.Post("http://ptsv2.com/t/ywexb-1620143951/post")
.Data(post)
// Send the request
.Execute();
cout << "GOT: " << reply->GetBodyAsString() << endl;
});
try
{
// Get the Post instance from the future<>, or any C++ exception thrown
// within the lambda.
done.get();
}
catch(const exception& ex)
{
cout << "Main thread: Caught exception from coroutine: "
<< ex.what() << endl;
}

错误发生在";张贴";数据结构串行化在下面的"函数中;SerializeJson.h";文件

template <typename dataT, typename serializerT>
void do_serialize(const dataT& object, serializerT& serializer,
const serialize_properties_t& properties,
typename std::enable_if<
!boost::fusion::traits::is_sequence<dataT>::value
&& !std::is_integral<dataT>::value
&& !std::is_floating_point<dataT>::value
&& !std::is_same<dataT, std::string>::value
&& !is_container<dataT>::value
&& !is_map<dataT>::value
>::type* = 0) {
assert(false);
};

1273行在断言上。

有人有主意吗?

提前感谢

我发现了错误。我已经阅读了type_traits标准库中关于enable_if的文档。它似乎是对integral_type、floating_point等的检查。。。在中

...
typename std::enable_if<
!boost::fusion::traits::is_sequence<dataT>::value
&& !std::is_integral<dataT>::value
&& !std::is_floating_point<dataT>::value
&& !std::is_same<dataT, std::string>::value
&& !is_container<dataT>::value
&& !is_map<dataT>::value
>::type* = 0)
...

在我的原始代码中,我给出了数据函数的Post结构

Post post;
post.i = 22;
...
auto reply = RequestBuilder(ctx)
.Post("http://ptsv2.com/t/ywexb-1620143951/post")
.Data(post)
// Send the request
.Execute();

我直接用一个";int";而且还可以。然后,我阅读了restc-cpp文档,并在Post结构定义后的结构中添加了BOOST_FUSION_ADAPT_STRUCT宏和字符串:

struct Post
{
int i;
string name;
};
BOOST_FUSION_ADAPT_STRUCT(
Post,
(int, i)
(string, name)
)

帖子请求成功了!

我希望它能帮助别人!

最新更新