First Missing Key Now Reported
When error_on_missing_keys = true we now report the first missing key.
Console output of glz::format_error when "hello" key is missing:
1:33: missing_key
[{"i":287,"d":0.0,"arr":[1,2,3]}]
^ hello
- In #1766
New glz::cast wrapper for static casting fields
This provides cleaner syntax than using glz::custom.
glz::cast is a simple wrapper that will serialize and deserialize the cast type rather than underlying type. This enables the user to parse JSON for a floating point value into an integer, or perform similar static_cast behaviors.
struct cast_obj
{
int integer{};
};
template <>
struct glz::meta<cast_obj>
{
using T = cast_obj;
static constexpr auto value = object("integer", cast<&T::integer, double>);
};In use:
cast_obj obj{};
std::string buffer = R"({"integer":5.7})";
expect(not glz::read_json(obj, buffer));
expect(obj.integer == 5);- In #1758
Integer IDs for std::variant
Previously only JSON strings could be used as IDs for std::variant. Now, this is possible:
struct Command401
{
int code{};
int indent{};
std::vector<std::string> parameters{};
};
struct Command250Params
{
std::string name{};
int volume{};
int pitch{};
int pan{};
};
struct Command250
{
int code{};
int indent{};
std::vector<Command250Params> parameters{};
};
using CommandVariant = std::variant<Command250, Command401>;
template <>
struct glz::meta<CommandVariant>
{
static constexpr std::string_view tag = "code";
static constexpr std::array ids = {250, 401};
};Glaze will decode the proper type based on the tag's field, e.g. "code": 401 will parse a Command401 type.
- In #1764
Other Improvements
- Equality operators for glz::async_vector by @stephenberry in #1757
Fixes
- Remove bad unit test causing GCC 15 compilation failure by @stephenberry in #1763
Full Changelog: v5.3.0...v5.3.1