序列化外部对象
我正在针对 Bloomberg Desktop Java API 进行编程,在该 API 中,我通过 API 订阅并接收 Message
对象中的市场数据,其中包含不同的字段和不同类型的相应值。我想“记录”一系列消息,以便可以通过重放已知的消息序列来测试处理这些对象的代码。理想情况下,我想在一天中订阅多条消息并将它们放入 ArrayList (或类似的)中,然后序列化对象列表。但是,Message
对象没有实现 Serialized
接口,因此这似乎没有按照我想要的方式工作。
是否可以或者是否有任何解决方法来序列化未实现 Serialized
的外部对象。谢谢。
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 the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以包装
Message
对象并实现 Externalized 接口,您可以在readExternal/writeExternal
方法中编写序列化/反序列化逻辑。You can wrap the
Message
object and implement Externalizable interface, whereby you can write the serialization/deserialization logic inreadExternal/writeExternal
methods.据我所知,最简单的方法是xStream。这是 xStream 网站上专门针对此问题的 FAQ
The simplest way that I know of is xStream. Here is a FAQ from the xStream website specifically about this