Skip to content

Add preparer for serialize #329

@digitalresistor

Description

@digitalresistor

Currently when you serialize values, there is no preparer step before passing it off to the sub-types (in the case of the MappingSchema)

colander/colander/__init__.py

Lines 2276 to 2293 in 141263a

def serialize(self, appstruct=null):
""" Serialize the :term:`appstruct` to a :term:`cstruct` based
on the schema represented by this node and return the
cstruct.
If ``appstruct`` is :attr:`colander.null`, return the
serialized value of this node's ``default`` attribute (by
default, the serialization of :attr:`colander.null`).
If an ``appstruct`` argument is not explicitly provided, it
defaults to :attr:`colander.null`.
"""
if appstruct is null:
appstruct = self.default
if isinstance(appstruct, deferred): # unbound schema with deferreds
appstruct = null
cstruct = self.typ.serialize(self, appstruct)
return cstruct

this means we can not influence the appstruct before passing it off to the various subtypes in the mapping schema

https://github.com/Pylons/colander/blob/master/colander/__init__.py#L811-L818

This doesn't match the deserialize API which has a preparer function that can be used to modify the cstruct before passing to children and or validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions