简体   繁体   English

序列化外部对象

[英]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. 我正在编写Bloomberg Desktop Java API,我订阅并接收Message对象中的市场数据,包含不同的字段和不同类型的相应值,通过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 the list of objects. 理想情况下,我想在一天内订阅一些消息并将它们放入ArrayList (或类似的)中,然后序列化对象列表。 However, the Message object does NOT implement the Serializable interface so this does not appear to work the way I want it to. 但是, Message对象没有实现Serializable接口,所以这看起来不像我想要的那样工作。

Is it possible, or is there any workaround, to serialize external objects that do not implement Serializable . 序列化不实现Serializable外部对象是否可行,或者是否有任何解决方法。 Thanks. 谢谢。

您可以包装Message对象并实现Externalizable接口,从而可以在readExternal/writeExternal方法中编写序列化/反序列化逻辑。

The simplest way that I know of is xStream . 我所知道的最简单的方法是xStream Here is a FAQ from the xStream website specifically about this 以下是来自xStream网站的常见问题解答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM