0
CreateOrderRequest req = new CreateOrderRequest();
req.pid=1111;
req.name="xxx";
TMemoryBuffer mem_buf = new TMemoryBuffer(512);
TJSONProtocol bin_proto = new TJSONProtocol(mem_buf,true);
try
{
req.write(bin_proto);
System.out.println("====begin serial json=================");
String jsonStr=mem_buf.toString("utf-8");
System.out.println("after jasonprocol="+jsonStr);
System.out.println("====begin deserial json=================");
CreateOrderRequest req2 = new CreateOrderRequest();
TMemoryBuffer mem_buf2 = new TMemoryBuffer(512);
byte[] data = jsonStr.getBytes();
mem_buf2.write(data);
TJSONProtocol bin_proto2 = new TJSONProtocol(mem_buf2,true);
req2.read(bin_proto2);
System.out.println("after de jasonprocol pid="+req.pid);
System.out.println("after de jasonprocol name="+req.name);
}
catch(Exception e)
{
System.out.println(e);
}
====begin serial json=================
after jasonprocol={"pid":{"i32":1111},"uid":{"i32":0},"corpId": {"i32":0},"sharePriceE6":{"i64":0},"shareCount":{"i32":0},"totalPriceE6":{"i64":0},"bankcardId":{"i32":0},"name":{"str":"xxx"},"isAnonymous":{"tf":0},"expectIncomeE6":{"i64":0},"clientId":{"i32":0},"totalAmtE6":{"i64":0},"subSrc":{"str":""}}
====begin deserial json=================
org.apache.thrift.protocol.TProtocolException: Unexpected character:p
질문 :
fieldNamesAsString_ 후, true로 설정되어 있지 않은 경우 jasonStr
은 {"1": {"i32":1111},"2":{"i32":0},"3":{"i32":0},...
이되며 CreateOrderRequest에 다시 기록 할 수 있습니다. 합리적이라고 생각하지 않습니다.
개체를 json str에 쓸 수는 있지만 다시 읽을 수는 없습니까?
감사합니다,하지만 난 직렬화 메소드를 구현하기가 매우 복잡 할 수 없습니다 생각, 그리고 왜 그것을 할? 왜냐하면 TField는 thriftId와 fiedName, – robin
@robin을 모두 저장했기 때문입니다. "* 구현하기가 너무 복잡하지 않을 것 같아요."- 이것은 오픈 소스이기 때문에 그냥 발사하십시오! [끌어 오기 요청을 환영합니다.] (https://thrift.apache.org/docs/HowToContribute). – JensG