Class: Gitlab::Database::Type::JsonPgSafe

Inherits:
ActiveRecord::Type::Json
  • Object
show all
Defined in:
lib/gitlab/database/type/json_pg_safe.rb

Overview

Extends Rails’ ActiveRecord::Type::Json data type to remove JSON encooded nullbytes ‘u0000` to prevent PostgreSQL errors like `PG::UntranslatableCharacter: ERROR: unsupported Unicode escape sequence`.

Example:

class SomeModel < ApplicationRecord
  # some_model.a_field is of type `jsonb`
  attribute :a_field, Gitlab::Database::Type::JsonPgSafe.new
end

Instance Method Summary collapse

Instance Method Details

#serialize(value) ⇒ Object



18
19
20
# File 'lib/gitlab/database/type/json_pg_safe.rb', line 18

def serialize(value)
  super&.gsub('\u0000', '')
end