1. 程式人生 > >Hessian序列化詳解

Hessian序列化詳解

簡單示例

com.spy.test.hessian.User

public class User implements Serializable {
    private Long    userId;
    private String  userCode;
    private String  userName;
    private String  email;
    private Integer age;

    private List<String> roles;
}

List<String> roles = Arrays.asList("admin"
); user = User.builder() .userId(1L) .userCode("0001") .userName("cc") .age(20) .roles(roles) .build();

輸出的碼流

[67, 25, 99, 111, 109, 46, 115, 112, 121, 46, 116, 101, 115, 116, 46, 104, 101, 115, 115, 105, 97, 110, 46, 85, 115, 101, 114, -106, 6
, 117, 115, 101, 114, 73, 100, 8, 117, 115, 101, 114, 67, 111, 100, 101, 8, 117, 115, 101, 114, 78, 97, 109, 101, 5, 101, 109, 97, 105, 108, 3, 97, 103, 101, 5, 114, 111, 108, 101, 115, 96, -31, 4, 48, 48, 48, 49, 2, 99, 99, 78, -92, 113, 26, 106, 97, 118, 97, 46, 117, 116, 105, 108, 46, 65, 114, 114, 97, 121, 115, 36, 65
, 114, 114, 97, 121, 76, 105, 115, 116, 5, 97, 100, 109, 105, 110]

現在對碼流進行分析,其實也是對hessian序列化的分析


67:C ,代表class

25, 全類類名長度 
99, 111, 109,  com
46, 
115, 112, 121, spy
46, 
116, 101, 115, 116, test 
46, 
104, 101, 115, 115, 105, 97, 110,:hessian 
46, 
85, 115, 101, 114:User

-106, 類中欄位個數(6個欄位+1446, 
117, 115, 101, 114, 73, 100,  欄位名稱 userId
8, 
117, 115, 101, 114, 67, 111, 100, 101, userCode
8, 
117, 115, 101, 114, 78, 97, 109, 101, userName
5, 
101, 109, 97, 105, 108,  email
3, 
97, 103, 101, age
5, 
114, 111, 108, 101, 115, roles 
96, (96+00是引用次數


-31, 1
4, 48, 48, 48, 49, 
2, 99, 99, 
78 , N email欄位為null
-92, age=20
113, (112+1) list大小 java.util.Arrays$ArrayList
26, list type大小(即java.util.Arrays$ArrayList的長度)
106, 97, 118, 97, 46, 117, 116, 105, 108, 46, 65, 114, 114, 97, 121, 115, 36, 65, 114, 114, 97, 121, 76, 105, 115, 116, (即java.util.Arrays$ArrayList)
5, 
97, 100, 109, 105, 110(admin)