0
자바 객체 직렬화 할 수 없습니다 내가 JSON 문자열을 자바 객체를 직렬화 한 후 다시 JSON 문자열을 역 직렬화하려고 자바 코드를 작성 드리프트는 JSON에서 나는 다음과 같은 중고품 객체에서 자바 객체를 생성
struct Account {
1: required string accountType,
2: bool accountActive,
}
to java 객체. 내가 성공적으로 serialize 할 수 있지만 deserialize하지 못했습니다.
Exception in thread "main" org.apache.thrift.protocol.TProtocolException: Required field 'accountType' was not present! Struct: Account(accountType:null, accountActive:false)
사람이 나에게 문제의 의미를 알아내는 데 도움 수 :
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());
그것은 다음과 같은 예외를 던지는 계속? 미리 감사드립니다.
json으로 문자열이 Java 오브젝트에서 절약 직렬화인지 결과 { "ACCOUNTTYPE": "P", "accountActive가"1} – dereck