Closed clabnet closed 3 years ago
What version of msvc are you using? I don't know what is wrong. I wrote a small program to test this out, and it compiled for me:
#include <string>
#include <json_struct.h>
const char json[] = R"json(
{
}
)json";
namespace licmgrapi
{
struct Module
{
std::string key;
double value;
JS_OBJ(key, value);
};
struct Config
{
std::string webInterface = "0.0.0.0";
int webPort = 9898;
std::string apiKey = "xxxyyyzzz";
std::string productId = "xxxxxxxxxx";
std::string productVersion = "0.1";
std::string licFile = "licfiles\\licfile_9001494765.lic";
bool useSwagger = false;
std::string revalidate = "0 */30 * * * ?";
int thresholdOfflineHours = 48;
int thresholdValidatedHours = 720;
int cicoModule = -1;
std::vector<Module> moduleList;
Config() {}
Config(int argc, char* argv[]);
JS_OBJECT(
JS_MEMBER(webInterface),
JS_MEMBER(webPort),
JS_MEMBER(apiKey),
JS_MEMBER(productId),
JS_MEMBER(productVersion),
JS_MEMBER(licFile),
JS_MEMBER(useSwagger),
JS_MEMBER(revalidate),
JS_MEMBER(thresholdOfflineHours),
JS_MEMBER(thresholdValidatedHours),
JS_MEMBER(cicoModule),
JS_MEMBER(moduleList)
);
};
}
int main()
{
licmgrapi::Config obj;
JS::ParseContext parseContext(json);
if (parseContext.parseTo(obj) != JS::Error::NoError)
{
std::string errorStr = parseContext.makeErrorString();
fprintf(stderr, "Error parsing struct %s\n", errorStr.c_str());
return -1;
}
std::string json_string = JS::serializeStruct(obj);
return 0;
}
Thanks for your support.
C++17 on Visual Studio 2019 Toolset 142.
"Missing JS_OBJECT JS_OBJECT_EXTERNAL or TypeHandler specialisation\n");
Hi,
Turned out I had forgotton to add the TypeHandler for std::shared_ptr. I have updated the master branch to contain this now, and all should be good 👍
Hi, I have this struct into a variable
cfg_
The JS::ParseContext parseContext(jsonData) is ok, but I try to serialize it to obtain a JSON string:
I have these errors on build:
What I'm missing ?
Thanks in advance