Skip to content

Different serialization/deserialization rules #119

Closed Answered by stephenberry
klemenpeganc asked this question in Q&A
Discussion options

You must be logged in to vote

@klemenpeganc

To explain @mwalcott3 answer further:

This kind of custom reading/writing is best handled by implementing your own from_json and to_json specializations within the glz::detail namespace.

Here is a very simplified example of your problem:

// custom type handling
struct date
{
   uint64_t data;
   std::string human_readable;
};

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

namespace glz::detail
{
   template <>
   struct from_json<date>
   {
      template <auto Opts>
      static void op(date& value, auto&&... args)
      {
         read<json>::op<Opts>(value.human_readable, args...);
        …

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@stephenberry
Comment options

Answer selected by mwalcott3
Comment options

You must be logged in to vote
1 reply
@stephenberry
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants