Implementing Towards Better Serialization

Brian Goetz brian.goetz at oracle.com
Mon Aug 10 15:29:27 UTC 2020


> Thanks, this is really interesting, and I must admit I probably get at most 80%. Are there any texts you can suggest as a starting point to domain theory or category theory? 

This paper: https://arxiv.org/abs/1807.02786 <https://arxiv.org/abs/1807.02786> isn’t a bad start.

> So if I get this right, my job as a designer of an interoperable serialization schema is to create a schema S that is an embedded projections pair of multiple programming language domains B. And to take it a step further, the encoded data of an object is the embedded projection pair of the internal representation of that object, and that internal representation is the embedded projection pair of the target object we started with. Am I generalizing this construct a bit too far?

The e-p design is more on the part of the class author.  As a schema designer, you want to consume e-p pairs, which you are synthesizing from ctor/dtor pairs, or ctor/accessor bundles.  And hoping they have the algebraic properties you want, because this is what makes serializing + deserializing yield an “equivalent” object.  

> That starts to look a lot like a chance for type cast operator overloading. Are these the droids I'm looking for? :) It would then be possible to cast Header into the serialized form:
> 
>   Serialized serialized = (Serialized) header;
> 
> and back again:
> 
>   Header header = (Header) serialized;
> 
> Where S == B for an object, it can return the object. 

Many types that have conversions A->B and B->A form e-p pairs too, such as ArrayList / List (or any pair of types related by a widening conversion), int / long, int / double, int / Integer, etc.  The key is that you can round trip in one direction always, and in the other direction modulo a first “bad trip” (such as unboxing null (NPE), or truncating 3.14 to 3.  Once you take that first bad trip, you can keep round-tripping in that direction too.  This describes a lot of real-world conversions, and it’s what you want for supporting serialization.  




More information about the amber-dev mailing list