public static void main(String[] args) throws IOException { UserStruct stu = new UserStruct(); stu.DeviceID = "DeviceID"; stu.Password = "Password"; MessagePack pack = new MessagePack(); //序列化 byte[] bytes = pack.write(stu); //反序列化 UserStruct s = pack.read(bytes, UserStruct.class); System.out.println("DeviceID: "+s.DeviceID); }
import java.io.Serializable; import org.msgpack.annotation.Message; @Message public class UserStruct implements Serializable { public String Password; public String DeviceID; public UserStruct() { } }
注意:msgpack-java 須要經過註解的方式表示序列化對象java