Comments (19)
You have a great library. This library is exactly what I've been wanting for working with json in C++. It just seems like it's not quite ready to use yet. Keep working on it!
from json_struct.
I have tried to reproduce this on Ubuntu 22.04, but without luck. Can you tell me something about the system you are running this on. Can you run this in a debugger and inspect the callstack, or open the generated coredump? Maybe you could send me the coredump? I have tried this in the range {0..1000} but showing 25 here for readabillity.
from json_struct.
Just noticed the c++20 version. I have recompiled with c++20 with no change in the output.
from json_struct.
Sorry, I'm very confused. It is 100% reproducible on my system, fails on the first try every time. I have run it in a debugger. The errors change based on what other members are in the structure. I am using google test, not sure if that makes a difference.
from json_struct.
The way it is failing at the moment is to throw a "bad_alloc" exception. In the debugger, handle_json_escapes_out
calls buffer.reserve(data.size()+10)
in line 4755. data.size() returns a gigantic number for the string, so the reserve() call fails.
from json_struct.
There is something very odd going on. The TypeHandler for std::string is being called, but there are no string members in struct Simple! Do you have the sample Simple struct as the one in the initial example?
from json_struct.
struct Simple
{
std::vector<int> v;
JS_OBJECT(JS_MEMBER(v));
};
const char expected1_compact[] = R"json({"v":[1,2,3,4,5,6,7,8,9]})json";
TEST_F(EsiJsonSerdesGTest, Struct2Json)
{
std::vector<int> temp_vect{1,2,3,4,5,6,7,8,9};
Simple simple;
simple.v = temp_vect;
std::string output = JS::serializeStruct(simple, JS::SerializerOptions(JS::SerializerOptions::Compact));
EXPECT_STREQ(output.c_str(), expected1_compact);
}
from json_struct.
As I was stepping through, I thought I saw something about a default constructor being called that created an empty string. I think it's trying to create the output string.
from json_struct.
oh, I think I know whats going on. Do you have another Simple struct in your executable? Try and put the entire test and definition of Simple in an anonymous namespace.
from json_struct.
Yes, a separate file has a struct named Simple:
struct Simple
{
std::string A;
bool b;
int some_longer_name;
JS_OBJECT(JS_MEMBER(A), JS_MEMBER(b), JS_MEMBER(some_longer_name));
};
from json_struct.
I changed the name of the struct from Simple to Simple2. This does indeed allow the test to pass.
struct Simple2
{
std::vector<int> v;
JS_OBJECT(JS_MEMBER(v));
};
const char expected1_compact[] = R"json({"v":[1,2,3,4,5,6,7,8,9]})json";
TEST_F(EsiJsonSerdesGTest, Struct2Json)
{
std::vector<int> temp_vect{1,2,3,4,5,6,7,8,9};
Simple2 simple;
simple.v = temp_vect;
std::string output = JS::serializeStruct(simple, JS::SerializerOptions(JS::SerializerOptions::Compact));
EXPECT_STREQ(output.c_str(), expected1_compact);
std::cout << output << std::endl;
}
from json_struct.
Yes, I believe you are violating the ODR. Either change the name, or put the struct definition and usage in a anonymous namespace or put the struct in a named namespace.
from json_struct.
The ODR applies to a source file, not an entire program. The struct Simple is only defined once per translation unit.
According to standard C++ (wayback machine link) : A translation unit is the basic unit of compilation in C++. It consists of the contents of a single source file,
https://stackoverflow.com/a/1106167/4541938
from json_struct.
ah, nvm. I think you are right.
from json_struct.
cool, is this also the problem your experiencing with the tuples?
from json_struct.
would be nice to have some sort of chat :)
from json_struct.
cool, is this also the problem your experiencing with the tuples?
I will revisit the tuple issue. I had copied/pasted some of the test cases from the repo. I need to go back and check for duplicate structure names. I will have to recreate the tuple test - I think I inadvertently overwrote my test case file with that test case in it. I've been switching back and forth today and I lost a file.. :-(
from json_struct.
np. I have been able to reproduce the compile error for serializing the std::tuple. I will look at that and fix it. I'm closing this issue if its ok with you.
from json_struct.
yes. Thanks for working the issue with me.
from json_struct.
Related Issues (20)
- Not compile at armv7 HOT 2
- Reading JSON which contains certain extraneous values breaks parsing HOT 6
- min and max ? HOT 3
- how to serialize std::map and std::set ? HOT 2
- does parseTo check struct members ? HOT 6
- GNUInstallDirs is required for CMAKE_INSTALL_DATAROOTDIR HOT 4
- JS_OBJ_EXT triggers "ISO C++11 requires at least one argument for the "..." in a variadic macro" warning HOT 7
- this doest NOT support serialize a std::map with an int as its key HOT 1
- Parsing std::vector<MyStruct*> HOT 3
- Cannot parse std::tuple<bool> HOT 2
- Invalid memory access when parsing message HOT 1
- Enum class support HOT 1
- JS_ENUM Defaults HOT 4
- build.sh script fails on Ubuntu 22.04 HOT 1
- Compilation fails if std::tuple member in struct HOT 3
- Adding js member listeners HOT 3
- nothing
- serial a class' private member HOT 4
- Compilation errors with GCC 14.1.1 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json_struct.