class Exception
def self.json_create(object)
def self.json_create(object) result = new(object['m']) result.set_backtrace object['b'] result end
def as_json(*)
Exception.json_create(x) # => #
\Method +JSON.create+ deserializes such a hash, returning a \Exception object:
x = Exception.new('Foo').as_json # => {"json_class"=>"Exception", "m"=>"Foo", "b"=>nil}
require 'json/add/exception'
returning a 2-element hash representing +self+:
\Method Exception#as_json serializes +self+,
see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
to serialize and deserialize a \Exception object;
Methods Exception#as_json and +Exception.json_create+ may be used
def as_json(*) { JSON.create_id => self.class.name, 'm' => message, 'b' => backtrace, } end
def to_json(*args)
{"json_class":"Exception","m":"Foo","b":null}
Output:
puts Exception.new('Foo').to_json
require 'json/add/exception'
Returns a JSON string representing +self+:
def to_json(*args) as_json.to_json(*args) end