持久化java对象最简单的方法是什么? [英] What's the easiest way to persist java objects?

查看:267
本文介绍了持久化java对象最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有java程序,其类目前是POJO并存储在易失性内存中。这些都需要坚持下去。据我所知,两个流行的选择是JDO和Java Persistence API。对于那些对SQL,Torque等知之甚少的人来说,这是向程序数据添加持久性的最简单方法吗?

Right now I have java program whose classes are currently POJOs and stored in volatile memory. These need to be persisted. As I understand it two popular choices are JDO and the Java Persistence API. For someone who know little about SQL, Torque, etc, which is the easiest way to add persistence to my program's data?

推荐答案

以序列化到文件系统的传统方法是使用 Java序列。但是,您需要实现 Serializable 无处不在。

The traditional way to serialise to the filesystem is to use Java Serialisation. However you need to implement Serializable everywhere.

更简单的解决方案是使用 XStream 。您不需要实现任何接口,并且大多数所有内容都可以串行化和反序列化而无需进一步干预。如果需要,您可以进一步自定义序列化。我曾经遇到的唯一问题是序列化内部类而不是故意序列化包含的外部类(这是由于隐含的这个引用)

A simpler solution is to serialise to XML (and then dump to the filesystem) using XStream. You don't need to implement any interfaces, and most everything serialises and deserialises without further intervention. You can further customise the serialisation if required. The only problem I've ever had is serialising an inner class without intentionally serialising the containing outer class (this is due to the implicit this reference)

这篇关于持久化java对象最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆