PerlDancer/Dancer2 — pull request #647 by LionsPhil (2014-07-31 17:59:24+00:00)
Title: Allow to/from_json to throw

```
Do not implement to/from_json in terms of the (de)serialize()
methods of a temporary Serializer instance, since the error
generated is lost and they will just return undef. Let them throw
instead so that the route code can handle the exception, or propagate
to general "route died" handling. Configuration options are still
merged in using a temporary instance.

Add test dependency on Test::Trap for testing exceptions.

Add unit tests for unserializable data for the JSON serializer.
```
Some considerations for review:
* Addresses issue #644 for the case where you are using to/from_json without it being set as your serializer (e.g. because you want to respect the configuration, but do not want to blanket handle complex returns from routes).
* The refactoring to `_merge_options` means that configuration can now affect *de*serialization as well. I'm not sure if this is desirable.
* I am not clear on what the *intended* behaviour is if you set up a serializer then return unserializable data from your route, so the test for this case is quite loose (and has a TODO). At the moment Dancer seems to be choking on an undef internally in this case, but fixing that seems like material for a separate commit.
* Should possibly do the same for YAML etc. if this is deemed to be an appropriate change.
* (First time I've done the pull request workflow, so I hope I've got this right!)