How to specify optional parameters for serialization ?

437 views
Skip to first unread message

Stefan Babinec

unread,
May 16, 2018, 8:36:34 AM5/16/18
to cereal serialization library
Hi guys.

I've got class which is de-serialized with standard function

template<class Archive> // public serialization (normal)
 
void serialize(Archive & ar)
 
{
 ar
(
 cereal
::make_nvp("parameter_1", parameter_1),
 cereal
::make_nvp("parameter_2", parameter_2),

 cereal
::make_nvp("parameter_3", parameter_3),

 cereal
::make_nvp("parameter_4", parameter_4),

 cereal
::make_nvp("parameter_5", parameter_5) );
 
}

But in my case "parameter_4" and "parameter_5" are optional.

They may or may not be in the input json string.

When I'm trying to de-serialize such incomplete json with missing some parameters I get Cerele error - that cannot find those missing parameters.

Is there any way how to specify that some parameters are optional and in the case that they are not part of json default values will be used ?

Thanks a lot in advance.

S.

w.shan...@gmail.com

unread,
May 24, 2018, 1:52:37 AM5/24/18
to cereal serialization library
There is not currently a built in way to support optional values in cereal. It's been discussed for a very long time here: https://github.com/USCiLab/cereal/issues/30

usrecru...@gmail.com

unread,
Jul 10, 2018, 6:05:17 PM7/10/18
to cereal serialization library
Hi All, 

I need a project manager SERIALIZATION for my client, let me know if you have someone.. 

Manjeet Singh
IT Solutions Inc, 
Reply all
Reply to author
Forward
0 new messages