1unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED 2 require 'json' 3end 4 5# Exception serialization/deserialization 6class Exception 7 8 # Deserializes JSON string by constructing new Exception object with message 9 # <tt>m</tt> and backtrace <tt>b</tt> serialized with <tt>to_json</tt> 10 def self.json_create(object) 11 result = new(object['m']) 12 result.set_backtrace object['b'] 13 result 14 end 15 16 # Returns a hash, that will be turned into a JSON object and represent this 17 # object. 18 def as_json(*) 19 { 20 JSON.create_id => self.class.name, 21 'm' => message, 22 'b' => backtrace, 23 } 24 end 25 26 # Stores class name (Exception) with message <tt>m</tt> and backtrace array 27 # <tt>b</tt> as JSON string 28 def to_json(*args) 29 as_json.to_json(*args) 30 end 31end 32