I'm new to the thrift. I need to convert my data object to a JSON string
with Thrift JSON
serialization.
I tried in this way.
TSerializer serializer = new TSerializer(new TSimpleJSONProtocol.Factory());
String json = serializer.toString(object_name);
In here is an error, that object_name
should be in TBase
. How can I resolve this ?
Next time, please post the exact error message (use copy+paste), this makes it easier for all of us.
Whatever you want to serialize with Thrift, must be an descendant of Thrift's
TBase
class. You achieve this by writing some Thrift IDL and save it as a file (e.g.MyDataStructs.thrift
):Next, you pass that file to the Thrift compiler and tell him to generate some C# code from it:
This gives you a class derived from TBase:
This is what Thrift expects.
If below is what your are doing then it should work. Check if you are doing this. Employee is a demo call here, you have to use your actual class.