-
Notifications
You must be signed in to change notification settings - Fork 199
Open
Description
Hello @stephenberry,I may have found another bug.
Descreibe my issue
You can see the code below:
int main() {
glz::json_t v = {{"test", 1.00}, {"test2", 1}};
std::cout << *glz::write_json(v);
return 0;
}Output is that:
{"test":1,"test2":1}
It seems that glz::json_t can't properly serialize the double type?
My current progress
I found that:
- double type will call this overload:
template <class T>
requires std::convertible_to<T, val_t> && (!std::derived_from<std::decay_t<T>, json_t>)
json_t(T&& val)
{
data = val;
}- integer type will call this:
template <class T>
requires std::convertible_to<T, double> && (!std::derived_from<std::decay_t<T>, json_t>) &&
(!std::convertible_to<T, val_t>)
json_t(T&& val)
{
data = static_cast<double>(val);
}- double type in struct still not work:
struct vv {
int t;
double tt;
};
int main() {
glz::json_t v = {{"test", 1.00}, {"test2", 1}};
std::cout << *glz::write_json(vv{.t = 1, .tt = 1.0}) << std::endl;
return 0;
}- I found a issue Encoding of double variables that happen to be integral #1592 ,and this question has already been raised.
At last,I noticed that you @stephenberry gave the suggestion to use glz::custom to do this, but this should be difficult to do in std::variant, my current approach is to work around this via glz::raw_json, but this may not be a good solution?
Metadata
Metadata
Assignees
Labels
No labels