Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MessagePack Java 0.6.X dynamic type

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

We know that Java is a statically typed language. Dynamic features can be achieved by entering Value MessagePack.

Value has a way to check its own type (isIntegerType (), isArrayType (), etc.) and also converts it to its own type (asStringValue (), convert (Template)).

This code can be viewed in 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report