I want to serialize several C++ objects into JSON, and deserialize them back. Obviously since C++ is lacking reflection, this can't be done automatically. I will need to somehow tell the serializer which data member goes into which JSON property.
I can do that with C++, but I'd rather use something like Protobuf's message to specify the mapping. Out of the many many JSON C++ libraries out there, is there one that support some sort of metadata that allows me to map the serialization process without implementing it myself?
You can simply use the JSON cpp or C files and use them as API. That is what I have done for my previous project. C++ does not come with inbuilt JSON support like JAVA.
So include the files and use the JSON function as APIs. You can build it separately and link it statically to your program. Go to the JSON home page for language wise files:
http://json.org/
For CPP files:
http://sourceforge.net/projects/jsoncpp/
i think its moved to git repo. The link is present there.
Hope this helps.
The ASN.1 tools from OSS Nokalva support JSON encoding rules for ASN.1 schemae.
You write an ASN.1 schema (protobufs schema are similar but inferior), compile it to whatever language you want (C++ in your case), and you get the bunch of classes that can serialise to/from JSON.
Not free I'm afraid.
ASN.1 is great - there's all sorts of encoding rules to suit all occasions.
Related
I am currently looking for a library in any language that allows me to create structured AFP documents but so far I have not found any
Previously I tried to use a library called afp.lib belonging to java but this structure the document but lost bytes which distorts the document
I hope the guide of some language that allows me the construction of AFP without loss of bytes. even just the library that allows me to do it
You can try https://github.com/yan74/afplib which is a JAVA library for reading and writing AFP. It is however very low-level so you get fine-grained access to all structured fields, triplets, and such. You need to have detailed knowledge on MO:DCA in order to make use of it. If you want to create documents a composer is better suited: Apache FOP
I would like to use protobuf with a C++ project I'm working on.
However, I don't like to work with the auto-generated classes protoc creates and prefer to stick with the POCOs I already have. This is because the POCOs are already in use in other parts of the code and I want to be able to switch the serialization mechanism with ease later on. But manually writing converters between POCOs and protobuf message classes seems tedious and wrong.
I want to know if there's a way to use protobuf to create a serializer - an auto-generated class that will be able to serialize and deserialize my POCOs, without bugging me with internals.
Thanks.
First, you may like Cap'n Proto better, it was created by one of Google's former Google Protocol Buffer maintainers. Worth looking into, anyway.
But otherwise, you really need to consider why you're using Google Protocol Buffers.
If you want to achieve the forward and backward compatibility, and to be able to open, then edit, then save an object that possibly a different person created, with a different version of your protocol buffer declaration, and then sent along to yet another person with an even different version of the declaration... then you need to just bite the bullet and use the generated C++ from the Google Protocol Buffer Compiler.
It's really not just a serialization format. It's specifically designed to make it easy living with different versions of your serialization, over time.
If you don't need that flexibility, and you don't like the generated code, you may want to consider a different serialization tool.
In C#, I use XSD2Code in order to:
generate automatically entities from XSD
generate methods which serialize/deserialize XML stream in these entities
Does it exist in the native C++ world?
I am looking for libs which work on Windows.
No, C++ has no such feature.
However, there are a plurality of libraries for C++ which provide everything you could possibly need. I am sure that at least several will exist to suit your XML needs (yuck!).
In particular, "CodeSynthesis XSD - XML Data Binding for C++" looks promising.
I get 1,120,000 Google results for xsd xml c++.
I just discovered YAJL project which just does what I need.
Read from stream
Callback on each valid parsed token
Reparse incomplete json when new data arrived
But I prefer C++. Of course I can use this library from C++ project and even write my own wrapper if I really want to but anyway native C++ is preferable.
I looked at JsonCPP but looks like it can't read incomplete json data from stream.
Is there any other C++ libraries for parsing json streams?
Some more requirements:
lightweight. boost or Qt are not suitable
I need something what I may freely use in commercial closed source software (mit, public domain, etc).
Support for not blocking read. or allow to feed data (append_incoming_data).
Recently I search library with similar requirements,
and actually found only 1.5 libraries that support such requirements:
https://github.com/kazuho/picojson
one header library, BSD licence, and have interface like this:
Iter parse(value& out, const Iter& first, const Iter& last, std::string* err);
so you can create append_incoming_data with a couple of lines of code.
https://github.com/dropbox/json11
one file library, licence similar to BSD, c++11 support, but interface
that allow parse partly arrived from network json it require patch:
https://github.com/dropbox/json11/pull/55
P.S.
lightweight. boost or Qt are not suitable
Actually, they are not suitable because of
allow to feed data
At now both Qt5 json and boost property_tree can not parse
half ready json.
Other options are
sjparser - the parsing is based on schema specified
JsonReader - plain event based parser
I'm tasked with reading Apple's property list files within a c++ application. Focusing primarily on the xml-type plist files specified in OS X, which mimic a xml-type implementation.. Apple's implementation of their property list is described here:
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/plist.5.html
I'm wondering if there are classes or libraries available that already can read this type of implementation within standard c++ (not Objective-C); hoping to find something rather than rolling our own. Are there any open-source implementations of this available?
PList files are not only mimicing XML, they are XML, including valid XML headers.
Any XML reader should be able to parse these files as a result. If you're looking for a logical class that abstracts the files, I'm not aware of any existing ones. Given Apple's documentation, you should be able to write one yourself with an XML reader, although it would take some work for full compatibility.
For topic starter it is too late, I know, but maybe it helps somebody
https://github.com/animetrics/PlistCpp
This is a C++ Property List (plist) serialization library (MIT license).
It supports both XML and binary versions of the plist format and is designed to
be cross platform with minimal dependencies.
Is that target-specific?
For Windows, there is a crude solution which consists of using the functions of iTunes dynamic libraries to parse plist files (either binary or plain text format work).
That's a code originally written to interface an iPod, but you can easily extract the few functions you are interested in.
The repository is on this project page: http://code.google.com/p/t-pot/
Look for the file iPoTApi.h and iPoTApi.cpp, the function TranslatePLIST of the class CiPoTApi.
I wish there were a better solution, at the time I tried to compile it from Apple's sources targeted at Windows but it is a real nightmare, and files are missing. So using their libraries was a considerable shortcut.