rails 3.0.9 ArgumentError (redundant UTF-8 sequence):

Hi guys, I have a simple controller

  def gmap     @intentsearches = Intentsearch.all     logger.info @intentsearches     respond_to do |format|       format.html {render :gmap}       format.xml {render :xml => @intentsearches }       format.json { render :json => @intentsearches }     end   end

and want a json response, but i do get the following error

Completed 500 Internal Server Error in 107ms

ArgumentError (redundant UTF-8 sequence):   app/controllers/intentsearches_controller.rb:103:in `gmap'   app/controllers/intentsearches_controller.rb:100:in `gmap'

Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms) Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (36.4ms) Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (40.7ms)

I am sending a http request with only one header param Accept : application/json

Does anyone know about this issue?

Best,

philip

Hi,

the problem occurs if you have columns with byte data. to exclude them of the serialization is used

def serializable_hash(options=nil)     options ||= {}     options.merge!( :except=> [:MY_BYTEDATA_COLUMN] ) if options[:except].blank?     super(options)   end

dc dieci wrote in post #1010652:

Hi guys, I have a simple controller

  def gmap     @intentsearches = Intentsearch.all     logger.info @intentsearches     respond_to do |format|       format.html {render :gmap}       format.xml {render :xml => @intentsearches }       format.json { render :json => @intentsearches }     end   end

and want a json response, but i do get the following error

Completed 500 Internal Server Error in 107ms

ArgumentError (redundant UTF-8 sequence):   app/controllers/intentsearches_controller.rb:103:in `gmap'   app/controllers/intentsearches_controller.rb:100:in `gmap'

Rendered

/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb

(1.0ms) Rendered

/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb

(36.4ms) Rendered

/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb

within rescues/layout (40.7ms)

I am sending a http request with only one header param Accept : application/json

Does anyone know about this issue?

Best,

philip

update: some more investigation revealed the following.

when i do call the to_json method in the console on a single object it all works fine. the error occurs only when i get a collection of objects.

ArgumentError: redundant UTF-8 sequence       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:130:in

`unpack'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:130:in

`escape'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:125:in

`gsub'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:125:in

`escape'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:68:in

`escape'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:173:in

`encode_json'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:47:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:77:in

`check_for_circular_references'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:45:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`encode_json'       from (irb):26:in `map'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`each'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`map'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`encode_json'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:47:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:77:in

`check_for_circular_references'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:45:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`encode_json'       from (irb):26:in `map'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`each'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`map'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:247:in

`encode_json'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:214:in

`encode_json'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:214:in

`map'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:214:in

`encode_json'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:47:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:77:in

`check_for_circular_references'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:45:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/json/encoding.rb:30:in

`encode'       from

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/core_ext/object/to_json.rb:15:in