Unable to deserialize a json string - cereal::RapidJSONException

251 views
Skip to first unread message

Rajesh Khan

unread,
Nov 16, 2020, 5:47:49 PM11/16/20
to cereal serialization library

This is my json string to an object

{ "connectionString" : "MyConnectionString", "value" :"MyVal" }

This is my class

struct Settings 
 {
   std::string connectionString;
   std::string value; 
   template<class Archive> 
   void serialize(Archive& ar) {
    ar(CEREAL_NVP(connectionString), CEREAL_NVP(value) ); 
    }
 };

And this is what I am doing:

std::ifstream ifs("Settings.json"); 
std::string content((std::istreambuf_iterator<char>(ifs)),(std::istreambuf_iterator<char>())); 
Settings settings; { 
  cereal::JSONInputArchive archive_in(ifs); 
  archive_in(settings); 
}

Any suggestion on what I might be doing wrong here ? The exception I get is at

document.h

 MemberIterator MemberEnd()              { CEREAL_RAPIDJSON_ASSERT(IsObject()); return MemberIterator(GetMembersPointer() + data_.o.size); }


Any suggestions on what I might be doing wrong ?

Alessio Massaro

unread,
Nov 16, 2020, 5:55:43 PM11/16/20
to Rajesh Khan, cereal serialization library
If you construct an instance in code and serialize it, what does the json look like?

--
You received this message because you are subscribed to the Google Groups "cereal serialization library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cerealcpp+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cerealcpp/226f7a20-e7d4-4ec5-bd4d-b10eec04c144n%40googlegroups.com.

Avon Dalitz

unread,
Nov 16, 2020, 6:12:21 PM11/16/20
to cereal serialization library
Hello! I believe that each parameter in "archive_in" needs to be identified as an object in JSON, like so

{
    "value0": {
        "connectionString": "",
        "value": ""
    }
}

Rajesh Khan

unread,
Nov 16, 2020, 6:24:35 PM11/16/20
to cereal serialization library
It looks like this
{
    "connectionString": "sdds",
    "val": "Mydevice"

Rajesh Khan

unread,
Nov 16, 2020, 6:26:24 PM11/16/20
to cereal serialization library
It looks like this
{
    "connectionString": "sdds",
    "value": "SomeValue"
}

On Monday, November 16, 2020 at 2:55:43 PM UTC-8 Alessio M wrote:

Rajesh Khan

unread,
Nov 16, 2020, 9:30:57 PM11/16/20
to Avon Dalitz, cereal serialization library
@Avon thanks this works. Is there a way for me to not have to make it an object ? (i.e) not use value0 and have cereal deserialize the string i am using ?
You received this message because you are subscribed to a topic in the Google Groups "cereal serialization library" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cerealcpp/8RWincRaG18/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cerealcpp+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cerealcpp/75cbc978-eb06-4947-8851-4e5cdc7420f1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages