Thrift JSON 序列化實現,只寫操作。
JSON 的弊端就是沒有類型信息,如對於一個整數,無法區分 short,int,long,double等。
@Test
public void test4() throws IOException, TException {
Person person = new Person();
person.setName("lgh");
person.setAge(28);
person.setIsMarried(true);
FileOutputStream fos = new FileOutputStream(new File("person.txt"));
TIOStreamTransport transport = new TIOStreamTransport(fos);
TSimpleJSONProtocol protocol = new TSimpleJSONProtocol(transport);
protocol.writeMessageBegin(new TMessage("methodName", TMessageType.CALL, 0));
person.write(protocol);
protocol.writeMessageEnd();
protocol.getTransport().flush();
fos.close();
}
["methodName", 1, 0, {
"name": "lgh",
"age": 28,
"isMarried": 1,
"like": ["足球", "籃球", "乒乓球"]
}]