jaimegildesagredo / booby

Data modeling and validation Python library
https://booby.readthedocs.org
Other
176 stars 18 forks source link

Allow fields to override the key used for serialization and deserialization #15

Closed paulmelnikow closed 10 years ago

paulmelnikow commented 10 years ago

I'm writing python bindings for the Capsule CRM API and came across this neat library. I like it – the patterns, the readable code, and that it's lightweight.

I found myself quickly needing this one, since I want to remap the keys between the API and the model.

I saw in your blog post that you're looking to add some serialization features. I'm thinking you'll probably incorporate serialization into the models and fields rather than adding a separate serialization layer – is that right?

Let me know what you think! If you like this approach I can write some automated tests. This is passing the existing tests.

paulmelnikow commented 10 years ago

I fixed a bug in what I wrote and wrote a test. I'm thinking overriding __init__ is not the best way to handle this, since it's only during deserialization that you need to map the kwargs. I'm going to try a different approach.

paulmelnikow commented 10 years ago

Updated with a new version.

paulmelnikow commented 10 years ago

I reworked this some more as I finished writing the API client. You can see my working version in this branch. Some of it obviously won't work. It seems that serializers need some context, so this source-key mapping can be performed when deserializing embedded objects. Do you know how you'd like to handle that?

I'm going to close this since I don't think it's exactly the right approach, but I'd be happy to collaborate on a design for serialization if you're interested.

jaimegildesagredo commented 10 years ago

Hi @paulmelnikow! Thank you for using booby and taking the time to implement this approach for data serialization.

I saw in your blog post that you're looking to add some serialization features. I'm thinking you'll probably incorporate serialization into the models and fields rather than adding a separate serialization layer – is that right?

Yep, I think that data serialization/deserialization should be incorporated into models and fields. And I'm pretty much in accordance with your implementation. Although it is true that in some cases it may be more complex (like with embedded models).

I opened an issue to start working in the design and implementation of serialization/deserialization based on your work here. Take a look at https://github.com/jaimegildesagredo/booby/issues/16 and let me know what you think ;)