#718 ✓resolved
Martin Gamsjaeger (snusnu)

[PATCH] dm-serializer support for ValidationErrors

Reported by Martin Gamsjaeger (snusnu) | December 17th, 2008 @ 02:50 PM


I just added the possibility for dm-serializer to serialize DataMapper::Validate::ValidationErrors objects.

This makes it possible now to do

display @article.errors, :status => 422

for :xml, :json, :yaml and :csv

However, I encountered a weird problem while writing #to_json. I initially wanted the #to_json method to simply look like:

def to_json(*args)
  opts = args.first || {}
  errors.to_json(opts) # errors is a Hash here

because I thought that this should do the trick (it actually works when playing in irb).

However, I always got wrong argument type Hash (expected Data) - (TypeError) when calling #to_json on the errors Hash.

I googled a bit, didn't really find a workaround (i tried the advice on http://blog.idearise.com/2008/09... ... no success) and so I decided to implement #to_json by hand. Which means it's probably buggy :-)

I'm sorry I haven't written any specs for it (yet). I did test it in the usecase where I needed it, though, and everything seems to work fine.

Also, there are still some comments inside the patch. If everything is fine, I'll be happy to clean it up and submit it again (later on today or on monday, I leave for a short skiing trip tommorrow, hooray :-)

cheers snusnu

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »


Referenced by