I generated a java object from the following thrift object:
struct Account {
1: required string accountType,
2: bool accountActive,
}
I wrote a java code trying to serialize java object to json string and then deserialize the json string back to java object. I can serialize successfully but failed to deserialize.
TSerializer serializer = new TSerializer(new TSimpleJSONProtocol.Factory());
TDeserializer deserializer = new TDeserializer(new TSimpleJSONProtocol.Factory());
Account a1 = new Account();
a1.setAccountType("P");
a1.setAccountActive(true);
String json = serializer.toString(a1);
System.out.println(json);
Account a2 = new Account();
deserializer.deserialize(a2, json, "UTF-8");
System.out.println(a2);
System.out.println(a2.getAccountType());
It keeps throwing the following exception:
Exception in thread "main" org.apache.thrift.protocol.TProtocolException: Required field 'accountType' was not present! Struct: Account(accountType:null, accountActive:false)
Can anyone help me figure out what's the issue? Thanks in advance!