1unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2  require 'json'
3end
4
5# Symbol serialization/deserialization
6class Symbol
7  # Returns a hash, that will be turned into a JSON object and represent this
8  # object.
9  def as_json(*)
10    {
11      JSON.create_id => self.class.name,
12      's'            => to_s,
13    }
14  end
15
16  # Stores class name (Symbol) with String representation of Symbol as a JSON string.
17  def to_json(*a)
18    as_json.to_json(*a)
19  end
20
21  # Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
22  def self.json_create(o)
23    o['s'].to_sym
24  end
25end
26