You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above only works of course if I pass my "Decimals" as strings in json, e.g.:
{ "myPrice": "43.2" }
What I'd really like to be able to do is pass "myPrice" as a number (i.e. not in quotes). I've tried a few different approaches, but it seems that number_float_t really has to be an IEEE floating point type (i.e. I can't see a way to "access" the underlying string buffer of the number).
Any pointers would be appreciated!
The text was updated successfully, but these errors were encountered:
Excellent, thanks! Another approach (totally a hack) I just figured out is to call j.dump() within the adl serializer.
Aside from that, do you have any suggestions for how to serialize an arbitrary precision decimal type? I.e. the following gives me the same problem as deserialization (I can only write as a string, not a number):
Hi,
Do you know if there is any way to provide a deserialization routine for number_float_t, where I can get access to the underlying json string?
Basically I have an arbitrary length Decimal class, and I can easily read this in from json as follows:
namespace nlohmann { template <typename T> struct adl_serializer<Decimal> { static void from_json(const json &j, Decimal& decimal) { decimal = Decimal::parse(j.get<std::string>()); } }; }
The above only works of course if I pass my "Decimals" as strings in json, e.g.:
{ "myPrice": "43.2" }
What I'd really like to be able to do is pass "myPrice" as a number (i.e. not in quotes). I've tried a few different approaches, but it seems that number_float_t really has to be an IEEE floating point type (i.e. I can't see a way to "access" the underlying string buffer of the number).
Any pointers would be appreciated!
The text was updated successfully, but these errors were encountered: