0

I am in search of a way to tell rails to parse json and jsonb data from postgresql column to a different Class or simply stop it from parsing it to an Hash as I won't use the hash.

I useread_attribute_before_type_cast, but the type cast is wasteful for my application.

Thank you

1
  • Try to specify String type: serialize :your_field, String Commented Mar 17, 2015 at 14:26

1 Answer 1

1

This is my finding, it is not complete but solve my problem. I wrotte/found a serializer to deal with the json column.

In the model:

serialize :profile, HashSerializer

And the serializer is defined like this:

class HashSerializer
  def self.dump(hash)
    hash.to_json
  end

  def self.load(hash)
    (hash || {}).with_indifferent_access
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.