java - Convert an object to a JSON string with thrift json serialization -


i'm new thrift. need convert data object json string thrift json serialization.

i tried in way.

tserializer serializer = new tserializer(new tsimplejsonprotocol.factory()); string json = serializer.tostring(object_name); 

in here error, object_name should in tbase. how can resolve ?

in here error, object_name should in tbase.

next time, please post exact error message (use copy+paste), makes easier of us.

how can resolve this?

whatever want serialize thrift, must descendant of thrift's tbase class. achieve writing thrift idl , save file (e.g. mydatastructs.thrift):

struct employee {     1: string name     2: string surname     3: i32 age } 

next, pass file thrift compiler , tell him generate c# code it:

thrift  -gen csharp  mydatastructs.thrift 

this gives class derived tbase:

public partial class employee : tbase {   private string _name;   private string _surname;   private int _age;    // properties   public string name {... }   public string surname  { ... }   public int age  { ... }    // details omitted    public void read (tprotocol iprot)   {     // generated code read() method   }    public void write(tprotocol oprot) {     // generated code write() method   }    public override string tostring() {     // generated code tostring() method   }  } 

this thrift expects.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -