I think you need a line:

```ruby
body = media_type == 'application/alps+json ? alps_document.to_json : alps_document.to_xml
```
and then use that in the rack response.