79740000

Date: 2025-08-19 13:54:25
Score: 0.5
Natty:
Report link

The main thing is: cereal is not intended to deserialize random jsons, but rather jsons it generated itself. It has specific fields and flags it adds to help itself, such as versions and tags.

In your particular case, the json is saved as if an int is written to it, but you are deserializing through an std::optional<int>, which cereal expects to look different. As @3CEZVQ mentioned in a comment, this includes an extra field telling it if the optional is actually populated or not.

The fact that the value of the int is optional does not make the field in the json optional. If what you intend is an actual missing json field, that is not the right approach. What you want is an optional NVP, of type int. To achieve that, I have been using the lovely Optional-NVP extension, available at Cereal-Optional-NVP. I am not the author nor affiliated in any way, but I've been using it for a few years now and it does exactly what you are asking. Just add those files to your cereal installation to gain the new macros

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @3CEZVQ
  • Low reputation (0.5):
Posted by: Blabba