我有一个运行良好的 GWT 项目,并且我使用了一堆共享类。在项目的这个阶段,我需要与其他库共享 POJO。
我决定将 POJO 放入库中。
public class Application implements IsSerializable {
// ....
}
由于这个库是技术中立的,我想摆脱 IsSerialized
和对 GWT 的依赖。这有道理吗?
我需要在项目的 GWT 方面做任何事情吗?
最佳答案
您可以使用标准的java.io.Serialized
接口(interface)来代替(现在有些过时的)IsSerialized
。引入它的原因是为了将 GWT RPC 序列化与 Java 序列化区分开来。来自 official FAQ entry关于这个主题:
- The semantics of GWT's serialization are much less sophisticated than standard Java serialization, and so to use
java.io.Serializable
as the marker interface would imply that GWT's serialization system is capable of more than it actually is.- Conversely, GWT's serialization mechanism is simpler than standard Java's, and so to use
java.io.Serializable
would imply that users have more to worry about (such as serialization version IDs) than they actually do.- GWT implements only a subset of the full Java JRE classes, and specifically implements nothing in
java.io
. To usejava.io.Serializable
as the GWT RPC serialization marker interface dilutes the message thatjava.io
is not usable within a GWT application.While each of the points above still hold, the GWT Team felt that the community was generally aware of these issues but preferred the convenience of being able to use the standard
java.io.Serializable
interface rather than to have their classes implement theIsSerializable
marker interface (...).
关于java - 带有 GWT 的 POJO 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23996217/