ThreeTen / threeten

This project was the home of code used to develop a modern date and time library for JDK8. Development has moved to OpenJDK and a separate backport project, threetenbp.
http://threeten.github.io/
191 stars 37 forks source link

Spec for serialization format #46

Closed RogerRiggs closed 12 years ago

RogerRiggs commented 12 years ago

The serialization format of all JSR 310 classes. Ser needs to be documented as part of the spec.

RichardWarburton commented 12 years ago

Email core libs when there's a format proposal.

RogerRiggs commented 12 years ago

Broaden the description to apply to serialization of all persistent classes; Previously only referred to the missing spec for TZ serialization.

RichardWarburton commented 12 years ago

Using a serialisation delegate, with a package scoped Ser class.

RichardWarburton commented 12 years ago

Implement the main package on a branch and then ask @RogerRiggs to get an internal Oracle reviewer

RichardWarburton commented 12 years ago

I have pushed a branch to https://github.com/RichardWarburton/threeten/tree/serialisation for @RogerRiggs to get an internal reviewer to look at. Overall process is documented in javadoc of javax.time.Ser.

jodastephen commented 12 years ago

Some comments.

Overall, I think this will produce effective and well-defined serialization forms.

RichardWarburton commented 12 years ago

Thanks for your comments Stephen, its pretty late my end so I'll fix those issues up tomorrow.

The enums approach runs under the assumption that the TCK will define an ordering for such classes.

RogerRiggs commented 12 years ago

I'll ask for more comments from other Oracle folks. Comments:

More later,

RogerRiggs commented 12 years ago

If the type byte is used for versioning then something (the type perhaps) will need to be passed to the read/writeExternal method so each class has enough information to deal with the data in the stream properly.
If new read/writeExternal methods would be needed then perhaps they should be named to include the version number so its clear what version of data they handle. Thanks to Brian G for his comments.

jodastephen commented 12 years ago

I'd note that the read/write external methods could all be moved to the Ser class. However, when I first came up with the pattern I found that using the current approach allowed better access to the internals of each class (less package scoped code).

Personally, I think that a version 2 of any of these specs is highly unlikely, as the state of the class pretty much defines the type, so any change to the state would need a different type.

RogerRiggs commented 12 years ago

While unlikely, it is prudent to make sure the versioning mechanism works before v2. The built-in serialization handles version skew in both directions since it must deal with older versions being able to interoperation with newer versions. It tolerates both adding fields and 'removing' fields. The stream protocol is robust in that it can handle missing and extra information without getting a stream corrupted error.

RichardWarburton commented 12 years ago

I've pushed updates to the branch in response to the feedback - see commit names for specifics - I think this fixes most raised issues.

RichardWarburton commented 12 years ago

I've pushed the necessary tests for the serialization format into this branch.

RogerRiggs commented 12 years ago

The handling of enum's is asymmetric. For each readExternal() method there should be a corresponding writeExternal(); adjecent in the code so it is easy to see they are complementary. Ser.writeInternal should call the Enum's writeExternal method and not shortcut it.

The usage of ZONE_ID_TYPE and ZONE_ID_FIXED_TYPE is matching implementation types not public types. That might be worthy of a comment. The names imply different types of ZoneId but the type is only used to reflect a customization serialization format that is more related to the implementation than the ZoneId.

jodastephen commented 12 years ago

Agreed to integrate Richard's code.

RogerRiggs commented 12 years ago

Is this integration still pending?

jodastephen commented 12 years ago

Yes. Not happened yet.

jodastephen commented 12 years ago

Merged branch (lots of git pain). Removed special enum handling. Simplified ZoneId handling. Regenerated bin files.