ActiveRecord to_json encoding

Question: Hi, our company is using Ruby 1.8.6 with Rails 2.2.2. Does anyone know how we can explicitly specify what encoding to use when calling .to_json on an ActiveRecord?

Description: We have some multibyte characters in our database. For example we have a table with a name column that has this French accented e: Café Records. When we serialize this object using ActiveRecord's to_xml() everything looks fine in the browser and with our json objects.

When we render JSON using to_json() we are seeing problems where the accented 'e' character is getting mangled and causes our calling web client to fail since it's expecting properly UTF-8 encoded characters.

What's actually stored in the database ? If you open up a console and find the relevant object in the database what does the name attribute contain ? I don't think that to_json does much more than spit out the data ActiveRecord already has.

Fred

That's not what I meant. What are the actual bytes stored in the database ? What encoding does the database think this column is in. If, in a ruby console, you inspect the bytes contained in the name column what do you see ?

Fred