Hessian序列化详解
程序员文章站
2024-03-24 11:55:52
...
简单示例
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个字段+144)
6,
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+0)0是引用次数
-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)
更多的协议规范可以参考hessian2规范
上一篇: jsonObject转换出错
下一篇: Hessian序列化对象的实例