Question

When I serialize a hash containing UTF8 strings, like this:

  poll.variants = {0 => 'тест',1 => '-тест-',2 => 'test # test "тест'}

to an ActiveRecord field, the resulting field contains:

--- 
0: !binary |
  0YLQtdGB0YI=

1: !binary |
  LdGC0LXRgdGCLQ==

2: !binary |
  dGVzdCAjIHRlc3QgItGC0LXRgdGC

The utf8 strings get treated as binary and base64 encoded for some reason. The collation on the field is utf8_general_ci, and I'm a bit disappointed.

Is there any way to make ActiveRecord :serialize human-readable yaml to the field?

Was it helpful?

Solution

Is there any way to make ActiveRecord :serialize human-readable yaml to the field?

No. Its Base64 encoded so as to encode arbitrary text (in any encoding) down to the lowest common denonimator, which is then safe to send across the wire and/or store in datastores that dont accept UTF-8 data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top