Signing¶
- class django_orjson.signing.OrjsonSerializer[source]¶
An orjson-based serializer for use with
django.core.signing.Pass it as the
serializerargument tosigning.dumps()andsigning.loads(), or the lower-level methodsSigner.sign_object()andSigner.unsign_object():from django.core import signing from django_orjson.signing import OrjsonSerializer token = signing.dumps({"user_id": 1}, serializer=OrjsonSerializer) data = signing.loads(token, serializer=OrjsonSerializer)
Warning
One-way migration
Migrating from Django’s
JSONSerializertoOrjsonSerializeris safe, but the reverse case is not.Tokens signed with
JSONSerializercan be verified and read byOrjsonSerializerwithout issue. But tokens signed withOrjsonSerializercan be silently misread byJSONSerializer.Django’s
JSONSerializer.loadsdecodes the payload as latin-1 before parsing, whileOrjsonSerializerwrites non-ASCII characters as raw UTF-8. If you switch back, any token payload containing non-ASCII data will be silently misread as mojibake. For example,héllowill becomehéllo, with noBadSignatureorUnicodeDecodeErrorraised.