Class: Serialbench::Serializers::Json::JsonSerializer
Instance Method Summary
collapse
#features, format, #generate_json, #library_require_name, #parse_object, #supports_generation?
#get_version, #initialize, #require_library, #stream_parse
Instance Method Details
#available? ⇒ Boolean
9
10
11
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 9
def available?
require_library('json')
end
|
#generate(object, options = {}) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 29
def generate(object, options = {})
require 'json'
if options[:pretty]
JSON.pretty_generate(object)
else
JSON.generate(object)
end
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 13
def name
'json'
end
|
#parse(json_string) ⇒ Object
24
25
26
27
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 24
def parse(json_string)
require 'json'
JSON.parse(json_string)
end
|
#supports_custom_types? ⇒ Boolean
50
51
52
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 50
def supports_custom_types?
false
end
|
#supports_pretty_print? ⇒ Boolean
42
43
44
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 42
def supports_pretty_print?
true
end
|
#supports_streaming? ⇒ Boolean
38
39
40
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 38
def supports_streaming?
false
end
|
#supports_symbol_keys? ⇒ Boolean
46
47
48
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 46
def supports_symbol_keys?
false
end
|
#version ⇒ Object
17
18
19
20
21
22
|
# File 'lib/serialbench/serializers/json/json_serializer.rb', line 17
def version
require 'json'
JSON::VERSION
rescue LoadError, NameError
'built-in'
end
|