The TaggedJSONSerializer used for session serialization is rather smart when it comes to preserving types that usually cannot be JSON-encoded. However, it still has the problem that dict keys are converted to strings.
>>> from flask.sessions import TaggedJSONSerializer
>>> tj = TaggedJSONSerializer()
>>> tj.loads(tj.dumps({123: u'blah'}))
{u'123': u'blah'}
I think it would make sense to also tag the key here:
elif isinstance(value, dict):
return dict((k, _tag(v)) for k, v in iteritems(value))
The one drawback I see is that there could be code relying on the implicit conversion right now..