stephenberry / glaze

Extremely fast, in memory, JSON and interface library for modern C++
MIT License
1.24k stars 124 forks source link

unexpected comma is generated when unknown field is empty #1428

Closed JimjunZhang closed 2 weeks ago

JimjunZhang commented 2 weeks ago

Hello,

I see one issue on the unknown field output. Here is the sample code:

struct my_struct
{
    int i = 287;
    std::unordered_map<std::string, std::string> unknown;

};
template <>
struct glz::meta<my_struct> {
    using T = my_struct;
    static constexpr auto value = glz::object(
        "i", &T::i
    );

    static constexpr auto unknown_write{ &T::unknown };
    //static constexpr auto unknown_read{ 
    //    &T::unknown 
    //};
};

my_struct obj;
std::string buffer;
auto ec = glz::write < glz::opts{ .prettify = true } > (obj, buffer);

The output is as below. There is an additional comma (,) was generated after the field "i" because of empty "unknown". Can it be fixed or any workaround?

{
   "i": 287,
}
stephenberry commented 2 weeks ago

Thanks for reporting this bug, will try to look into it soon.

stephenberry commented 2 weeks ago

Thanks again for reporting this! A fix has been merged in #1435