我們知道 Java 是一個(gè)靜態(tài)類型的語言。通過輸入?Value
?MessagePack能夠?qū)崿F(xiàn)動(dòng)態(tài)的特性。
創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)整合營銷推廣、網(wǎng)站重做改版、白云鄂網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、成都做商城網(wǎng)站、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為白云鄂等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
Value?
有方法來檢查自己的類型(isIntegerType()
,?isArrayType()
, 等...),同時(shí)也轉(zhuǎn)換為自己的類型 (asStringValue()
,?convert(Template))。
本代碼可以在?https://github.com/cwiki-us-demo/messagepack-6-demo-java/blob/master/src/test/java/com/insight/demo/msgpack/MessagePack6DynamicTyping.java?中查看。
package?com.insight.demo.msgpack; import?org.junit.Test; import?org.msgpack.MessagePack; import?org.msgpack.type.Value; import?org.msgpack.unpacker.Converter; import?org.slf4j.Logger; import?org.slf4j.LoggerFactory; import?java.util.ArrayList; import?java.util.List; import?static?org.msgpack.template.Templates.TString; import?static?org.msgpack.template.Templates.tList; /** ?*?MessagePack6Objects ?* ?*?@author?yhu ?*/ public?class?MessagePack6DynamicTyping?{ ????final?Logger?logger?=?LoggerFactory.getLogger(MessagePack6DynamicTyping.class); ????/** ?????*?Test?MessagePack6Objects ?????*/ ????@Test ????public?void?MessagePack6DynamicTyping()?{ ????????logger.debug("MessagePack6Objects?for?Objects"); ????????//?Create?serialize?objects. ????????List?src?=?new?ArrayList (); ????????src.add("msgpack"); ????????src.add("kumofs"); ????????src.add("viver"); ????????MessagePack?msgpack?=?new?MessagePack(); ????????? ????????try?{ ????????????//?Serialize ????????????byte[]?raw?=?msgpack.write(src); ????????????//?Deserialize?directly?using?a?template ????????????List ?dst1?=?msgpack.read(raw,?tList(TString)); ????????????//?Or,?Deserialze?to?Value?then?convert?type. ????????????Value?dynamic?=?msgpack.read(raw); ????????????List ?dst2?=?new?Converter(dynamic).read(tList(TString)); ????????}?catch?(Exception?ex)?{ ????????????logger.error("MessagePack?Serialization?And?Deserialization?error",?ex); ????????} ????} }
https://www.cwiki.us/display/Serialization/QuickStart+For+MessagePack+Java+0.6.X