mikeywaites / kim

Kim: A JSON Serialization and Marshaling framework
http://kim.readthedocs.org/en/latest/
Other
317 stars 17 forks source link

Attach roles to mappings opposed to serializers. #33

Closed mikeywaites closed 9 years ago

mikeywaites commented 9 years ago

Roles are currently specified in the Meta class of kim.serializers.Serializer. They provide a way to affect the fields used at run time in different scenarios. Equally they provide the user with a way to affect which fields are relevant for marshaling/serializing when operating on related objects and data structures.

This has ultimately made the Serializer class more powerful than the underlying mapping that it constructs which was not the original intention. Serializer should remain as syntactic sugar for easily creating Mapping objects in a re-usable way.

This enhancement will allow Mapping objects to accept and make use of roles as a way to manage which Types are mapped. Any Roles defined on the Serializer therefore are just the way to define a role on mapping.

https://github.com/mikeywaites/kim/blob/master/kim/mapping.py#L15 would accept a new roles kwarg which would contain a collection of Role objects as seen previously in the Serializer class.

Mapping would then define a method get_iterable which is called with an optional role identifier as a kwarg that would return a mapping constructed from the role or the default (all fields)

Serializer would simply pass any provided role straight onto the underlying mapping here

https://github.com/mikeywaites/kim/blob/master/kim/serializers.py#L178

mikeywaites commented 9 years ago

https://github.com/mikeywaites/kim/issues/15 this use case should also be covered in this enhancement

mikeywaites commented 9 years ago

https://github.com/mikeywaites/kim/issues/17 this use case should also be covered in this enhancement