江西网站建设,南昌网站建设技巧分享--jackson 反序列化

一、jackson 基础测试(简单对象反序列化)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第1张图片

结果为:

{"userid":"c4764ef5234440c0a5ce35ce24f0b94d","username":null,"password":null,"link":null,"createTime":1496392724773,"timestamp":1496392724773}

{"userid":"c4764ef5234440c0a5ce35ce24f0b94d","username":null,"password":null,"link":null,"createTime":1496392724773,"timestamp":1496392724773}

二、jackson 基础测试(list反序列化)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第2张图片

结果为:

[{"userid":"bec82f06ca3e426cb493f7ee06ca9a33","username":null,"password":null,"link":null,"createTime":1496393056593,"timestamp":1496393056593},{"userid":"bec82f06ca3e426cb493f7ee06ca9a33","username":null,"password":null,"link":null,"createTime":1496393056593,"timestamp":1496393056593}]

[{"userid":"bec82f06ca3e426cb493f7ee06ca9a33","username":null,"password":null,"link":null,"createTime":1496393056593,"timestamp":1496393056593},{"userid":"bec82f06ca3e426cb493f7ee06ca9a33","username":null,"password":null,"link":null,"createTime":1496393056593,"timestamp":1496393056593}]

三、jackson 基础测试(map反序列化)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第3张图片

结果为:

{"7a5fbc514f8f4aa6a31df3a849f0ccf9":{"userid":"7a5fbc514f8f4aa6a31df3a849f0ccf9","username":null,"password":null,"link":null,"createTime":1496393375369,"timestamp":1496393375369},"2aae62fe4e1c43e7bb83fa659144cafd":{"userid":"2aae62fe4e1c43e7bb83fa659144cafd","username":null,"password":null,"link":null,"createTime":1496393375369,"timestamp":1496393375369}}

{"7a5fbc514f8f4aa6a31df3a849f0ccf9":{"userid":"7a5fbc514f8f4aa6a31df3a849f0ccf9","username":null,"password":null,"link":null,"createTime":1496393375369,"timestamp":1496393375369},"2aae62fe4e1c43e7bb83fa659144cafd":{"userid":"2aae62fe4e1c43e7bb83fa659144cafd","username":null,"password":null,"link":null,"createTime":1496393375369,"timestamp":1496393375369}}

四、jackson 基础测试(JsonProperty)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第4张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第5张图片

结果为:

{"username":null,"password":null,"link":null,"createTime":1496394720011,"Userid":"2f22ba65b2f74456a47c1897dccf5f51","Time":null}

{"username":null,"password":null,"link":null,"createTime":1496394720011,"Userid":"2f22ba65b2f74456a47c1897dccf5f51","Time":null}

五、jackson 基础测试(Date 的@JsonSerialize和@JsonDeserialize)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第6张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第7张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第8张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第9张图片

结果为:

{"username":null,"password":null,"link":null,"createTime":"2017-06-02 17:22:18","Userid":"fb8a50be9c3f4f148c1a48619cc1a88e","Time":null}

{"username":null,"password":null,"link":null,"createTime":"2017-06-02 17:22:18","Userid":"fb8a50be9c3f4f148c1a48619cc1a88e","Time":null}

六、jackson 基础测试(Timestamp 的@JsonSerialize和@JsonDeserialize)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第10张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第11张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第12张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第13张图片

结果中可以看到Timestamp已经成功的序列化和反序列化了。

七、jackson 基础测试(@JsonIgnore)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第14张图片

结果为:

{"username":null,"password":null,"createTime":"2017-06-05 10:56:38","Userid":"0c7e018661854919882414c6d488f63f","Time":"2017-06-05 10:56:38"}

{"username":null,"password":null,"createTime":"2017-06-05 10:56:38","Userid":"0c7e018661854919882414c6d488f63f","Time":"2017-06-05 10:56:38"}

这里我们已经看到link属性已经忽略了。

八、jackson 基础测试(SerializationFeature.INDENT_OUTPUT)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第15张图片

结果为:

{

"username" : null,

"password" : null,

"createTime" : "2017-06-05 11:03:47",

"Userid" : "2d52c96585804b809103c95198e10588",

"Time" : "2017-06-05 11:03:47"

}

{"username":null,"password":null,"createTime":"2017-06-05 11:03:47","Userid":"2d52c96585804b809103c95198e10588","Time":"2017-06-05 11:03:47"}

我们可以明白这里属性是进行缩放排列的。默认是进行缩放排列。

九、jackson 基础测试

a.SerializationFeature.WRITE_ENUMS_USING_TO_STRING

b.SerializationFeature.WRITE_ENUMS_USING_INDEX

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第16张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第17张图片

结果为:

{

"userType" : 0,

"username" : null,

"password" : null,

"createTime" : "2017-06-05 11:12:32",

"Userid" : "01423140698d4bb78e608a697d139a5b",

"Time" : "2017-06-05 11:12:32"

}

{"userType":"admin","username":null,"password":null,"createTime":"2017-06-05 11:12:32","Userid":"01423140698d4bb78e608a697d139a5b","Time":"2017-06-05 11:12:32"}

SerializationFeature.WRITE_ENUMS_USING_TO_STRING:序列化枚举是以toString()来输出,默认false,即默认以name()来输出

SerializationFeature.WRITE_ENUMS_USING_INDEX:序列化枚举是以ordinal()来输出,默认false

十、jackson 基础测试(@JsonRootName)

江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第18张图片
江西网站建设,南昌网站建设技巧分享--jackson 反序列化_第19张图片

结果为:

{"userinfo":{"userType":"common","username":null,"password":null,"createTime":"2017-06-05 11:18:37","Userid":"834449dc8abd47fa882fd668e9ad72fc","Time":"2017-06-05 11:18:37"}}

这里我们看到已经将userinfo加入到序列化的字符串中

(必须设置Serialization.WRAP_ROOT_NAME的值为true);

江西特飞科技提供营销型网站、小程序开发、营销型手机网站建设、网站运营托管等服务,特飞十年打造良心的作品,更多可以关注公众号 江西特飞科技

你可能感兴趣的:(江西网站建设,南昌网站建设技巧分享--jackson 反序列化)