-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid deserialization #5
Comments
Try this signature for jsob_io function:
json_io(JSON_IO& io, A & a)
Pass A instance by ref.
9 сент. 2017 г. 11:49 AM пользователь "Vladislav Gerasimov" <
[email protected]> написал:
Hello
I have the following code:
class A {
public:
float f;
A() {}
A(float f) :
f(f) {}
};
namespace json_dto {
template<typename JSON_IO>
void json_io(JSON_IO& io, A a) {
io
& json::mandatory("f", a.f);
}
}
After
auto v1 = A(10.8);
auto v = json_dto::to_json(v1);
std::cout << v << std::endl;
auto v2 = json_dto::from_json<A>(v);
std::cout << json_dto::to_json(v2) << std::endl;
I get
{"f":10.800000190734864}
{"f":1041031353073664.0}
Could you please help, where is my mistake?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVt3Yj6c30BCEl90sT2Ro3ptH93xisSvks5sglEsgaJpZM4PR7o->
.
|
Thank you, it was my fault. One more question: is there a way to set precision for float and double values (for getting {"f":10.8})? |
in a current version there is no way to set precision. A cuple of times I've faced such issue I simply do such rounding myself. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
I have the following code:
After
I get
{"f":10.800000190734864}
{"f":1041031353073664.0}
Could you please help, where is my mistake?
The text was updated successfully, but these errors were encountered: