Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False means null #45

Merged
merged 2 commits into from Mar 28, 2012
Merged

False means null #45

merged 2 commits into from Mar 28, 2012

Conversation

chrneumann
Copy link

Related to #1

@mthurman
Copy link

Hey, I'm just starting to use colander to model some data and I'm having a hard time modeling optional string data because of this commit. I'm writing message board software and a post could be "in reply to" another post but it doesn't have to be.

I was trying something like this:

class PostSchema(colander.MappingSchema):
    reply_to = colander.SchemaNode(colander.String(), default=None, missing=None)

but now when I do

>>> PostSchema().serialize({'reply_to': None})

I get collander.null in the output which simplejson (obviously) doesn't understand how to parse to javascript null.

So my question is, am I modeling this optional string attribute wrong?

@chrneumann
Copy link
Author

There is no obvious string representation (and colander de/serializes from/to strings) for None. You could convert the colander.null values in your cstruct to your json serializer's none value. It depends on your specific problem. Maybe a default="" would be be o.k. also. It depends on whether you really need to keep the None values in your json representation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants