Fwd: Re: Towards better serialization
brian.goetz at oracle.com
Wed Jun 12 22:27:53 UTC 2019
> you want to serialize those data.
> You cannot be more decoupled than current serialization as it is purely
The mechanisms serialization gives you to control serialization are
readObject, writeObject, readResolve, writeReplace, etc. Which are all
purely imperative -- and couple state extraction / reconstruction with
stream reading and writing.
As a bonus, if you implement readObject (and any class with invariants
must, or else it is broken), you have to validate the arguments
explicitly in readObject, and as a bonus, you get to do it in a
completely different way than you do in the constructor.
Have you never actually used these methods? If you had, you'd never
describe serialization as "purely declarative."
>> serialization of records is transparent.
> Why only records?
Because with records, all the relevant protocols -- such as
construction, deconstruction, equality, hashing -- are derived from the
record's declared state description. Serialization is one of those
protocols that can be derived from the state description.
More information about the amber-dev