java - MessagePack and Immutable Objects -
i have many immutable domain objects private final fields , public getter methods. possible serialize them using messagepack implementation java?
i know @message
annotation supports public fields, hoping use @messagepackbeans
, @ordinalenum
annotations. when try , serialize 1 of objects, don't exception on .write
call, serialization fails. i've included complete example below.
is there doing wrong, or should give on trying use messagepack?
import java.io.ioexception; import org.msgpack.messagepack; import org.msgpack.annotation.messagepackbeans; import org.msgpack.annotation.ordinalenum; public class msgpacktest { @ordinalenum public static enum myenum { a; } @messagepackbeans public final static class myobject { private final string mystring; private final myenum myenum; public myobject(string mystring, myenum myenum) { this.mystring = mystring; this.myenum = myenum; } public string getmystring() { return mystring; } public myenum getmyenum() { return myenum; } } public static void main(string[] args) { final myobject obj = new myobject("abc", myenum.a); final messagepack msgpack = new messagepack(); try { final byte[] bytes = msgpack.write(obj); //bytes = [-112] myobject result = msgpack.read(bytes, myobject.class); //unreachable code - messagetypeexception thrown system.out.println("success: " + result); } catch (ioexception e) { e.printstacktrace(); } } }
Comments
Post a Comment