colander icon indicating copy to clipboard operation
colander copied to clipboard

default empty values don't work in serialize()

Open imbaczek opened this issue 10 years ago • 1 comments

e.g.

class Data(colander.MappingSchema):
    name = colander.SchemaNode(colander.Str(), missing='', default='')

works as expected on deserialization, but not on serialization, where the node becomes null instead of ''.

imbaczek avatar Jul 29 '14 11:07 imbaczek

possible fix

        cstruct = self.typ.serialize(self, appstruct)
        if cstruct is null:
            cstruct = self.default
        return cstruct

in SchemaNode.serialize

imbaczek avatar Jul 29 '14 11:07 imbaczek