monzo / response

Monzo's real-time incident response and reporting tool ⚡️
MIT License
1.52k stars 165 forks source link

Deserialize event payload for API rendering #182

Closed mattrco closed 4 years ago

mattrco commented 4 years ago

The payload starts life as an Incident or Event object, rendered to a JSON string, then stored as a text field.

To enable the JSON renderer in Django Rest Framework to render this as an object rather than a JSON-encoded string the easiest option is to deserialize the field prior to sending it to the renderer.

An alternative would be to override the from_db method on the Event model, but since we don't need to modify the payload anywhere, it's simpler to do this in the serializer.