3 ms·
> What I've come to prefer is for serialization to be implemented a the boundaries of your service, with your models at least somewhat isolated from any given s
by deathanatos 8y ago
> What I've come to prefer is for serialization to be implemented a the boundaries of your service, with your models at least somewhat isolated from any given serialization technique.
I think this is the right way to do it. Just like how UTF-8 to a string type is kept at the borders. Inevitably, someone comes along with a requirement that implies the first iteration of the data modeling was not only wrong, but backwards-incompatibly wrong.
It's hard to convince coworkers that it isn't code duplication though.
> Protobuf is a foot-gun here because it blends these roles in a way that's hard to get away from.
I'm not sure; in many ways it is just trying to give you a way to supply it the data to serialize with those models. I'd be nice to not have the "foot gun", but I'm not sure what such a serialization framework would look like.
- ninkendo 8y agoIMO the serializers should be their own standalone classes/modules which live separately from your application’s core types. You can invoke them when you need to do the serialization and keep parallel versions of them for legacy clients, etc. ActiveModel::Serializers work like this in Rails, although I haven’t tried any similar approaches in statically-typed languages where protobuf is so commonly used.
- aldarn 8y agoFor Python there's Marshmallow (https://github.com/marshmallow-code/marshmallow https://github.com/marshmallow-code/marshmallow) and Django REST Framework if you're using Django (http://www.django-rest-framework.org/api-guide/serializers/ http://www.django-rest-framework.org/api-guide/serializers/). Both of these work as you described.
- SamReidHughes 8y agoSerializers are just functions. Why do they need to be classes?