Class: Serialbench::Serializers::Json::BaseJsonSerializer
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- Serialbench::Serializers::Json::BaseJsonSerializer
- Defined in:
- lib/serialbench/serializers/json/base_json_serializer.rb
Direct Known Subclasses
JsonSerializer, OjSerializer, RapidjsonSerializer, YajlSerializer
Class Method Summary collapse
Instance Method Summary collapse
-
#available? ⇒ Boolean
Check if the JSON library is available.
-
#features ⇒ Object
JSON-specific features.
- #generate_json(object, options = {}) ⇒ Object
-
#library_require_name ⇒ Object
Subclasses should override this to specify their library name.
-
#parse_object(json_string) ⇒ Object
JSON-specific methods.
- #supports_custom_types? ⇒ Boolean
- #supports_generation? ⇒ Boolean
- #supports_pretty_print? ⇒ Boolean
- #supports_symbol_keys? ⇒ Boolean
Methods inherited from BaseSerializer
#generate, #get_version, #initialize, #parse, #require_library, #stream_parse, #supports_streaming?
Constructor Details
This class inherits a constructor from Serialbench::Serializers::BaseSerializer
Class Method Details
.format ⇒ Object
9 10 11 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 9 def self.format :json end |
Instance Method Details
#available? ⇒ Boolean
Check if the JSON library is available
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 54 def available? return @available if defined?(@available) @available = begin require library_require_name true rescue LoadError false end end |
#features ⇒ Object
JSON-specific features
23 24 25 26 27 28 29 30 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 23 def features { pretty_print: supports_pretty_print?, streaming: supports_streaming?, symbol_keys: supports_symbol_keys?, custom_types: supports_custom_types? } end |
#generate_json(object, options = {}) ⇒ Object
18 19 20 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 18 def generate_json(object, = {}) generate(object, ) end |
#library_require_name ⇒ Object
Subclasses should override this to specify their library name
49 50 51 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 49 def library_require_name raise NotImplementedError, 'Subclasses must implement #library_require_name' end |
#parse_object(json_string) ⇒ Object
JSON-specific methods
14 15 16 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 14 def parse_object(json_string) parse(json_string) end |
#supports_custom_types? ⇒ Boolean
44 45 46 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 44 def supports_custom_types? false end |
#supports_generation? ⇒ Boolean
32 33 34 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 32 def supports_generation? true end |
#supports_pretty_print? ⇒ Boolean
36 37 38 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 36 def supports_pretty_print? true end |
#supports_symbol_keys? ⇒ Boolean
40 41 42 |
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 40 def supports_symbol_keys? false end |