开发者

How to implement Serialization in java [closed]

开发者 https://www.devze.com 2023-02-14 17:29 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.开发者_C百科 Fo
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form.开发者_C百科 For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Hi i'm looking for any open source available to implement the best in class serialization.

I'm talking about , Is there any opensource(which is popular) which handles the serialization better .


Serialization is built in to java. For most classes you can simply implement java.io.Serializable and your classes "magically" becomes serializable. Then you can use java.io.ObjectOutputStream & java.io.ObjectInputStream to read and write your objects.

If you require custom serialization, then add the following methods to your class to override the serialization behavior. They have to match these signatures exactly:

private void writeObject(ObjectOutputStream out) throws IOException {
  //YOUR WRITE CODE HERE
}

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  // YOUR READ CODE HERE
}


Either have a look at the Java source code (Yes, it comes with the JDK, but is zippen in a file called src.zip), or look at JBossSerialization, which is faster and reduces the size of the serialized objects. I have written my own some time ago, which is 6 times faster and produces 6 times less data, but it requires the exact class structure to be known to both sides, so it is just usable as a communication protocol and not for persistant storage.


Are you looking for something like protobuf? As other commenters have, I'm having a hard time with your question as originally written.

0

精彩评论

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