开发者

Serialize an external object

I am programming towards the Bloomberg Desktop Java API where I subscribe to and recieve market data in Message objects, containing different fields and corresponding values of different types, through the API. I want to 'record' a sequence of messages so that I can conduct testing of my code that processes these objects by replaying a known sequence of messages. Ideally, I would like to subscribe to a number of messages during a day and put them into an ArrayList (or similar) and then serialize t开发者_Go百科he list of objects. However, the Message object does NOT implement the Serializable interface so this does not appear to work the way I want it to.

Is it possible, or is there any workaround, to serialize external objects that do not implement Serializable. Thanks.


You can wrap the Message object and implement Externalizable interface, whereby you can write the serialization/deserialization logic in readExternal/writeExternal methods.


The simplest way that I know of is xStream. Here is a FAQ from the xStream website specifically about this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜