Class: Serialbench::Serializers::Json::BaseJsonSerializer

Inherits:
BaseSerializer
  • Object
show all
Defined in:
lib/serialbench/serializers/json/base_json_serializer.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.formatObject



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

Returns:

  • (Boolean)


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

#featuresObject

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, options = {})
  generate(object, options)
end

#library_require_nameObject

Subclasses should override this to specify their library name

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)


44
45
46
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 44

def supports_custom_types?
  false
end

#supports_generation?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 32

def supports_generation?
  true
end

#supports_pretty_print?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


40
41
42
# File 'lib/serialbench/serializers/json/base_json_serializer.rb', line 40

def supports_symbol_keys?
  false
end