Class: Lutaml::Json::Adapter::OjAdapter
- Inherits:
-
Document
- Object
- KeyValue::Document
- Document
- Lutaml::Json::Adapter::OjAdapter
- Defined in:
- lib/lutaml/json/adapter/oj_adapter.rb
Instance Attribute Summary
Attributes inherited from KeyValue::Document
Class Method Summary collapse
Instance Method Summary collapse
-
#ignores_generator_options? ⇒ Boolean
rubocop:disable Style/ArgumentsForwarding -- anonymous * requires Ruby 3.2+ Oj has its own option namespace and its own escape_mode.
- #to_json(*args) ⇒ Object
Methods inherited from KeyValue::Document
#[], #[]=, #initialize, #key?, #to_h
Constructor Details
This class inherits a constructor from Lutaml::KeyValue::Document
Class Method Details
.parse(json, _options = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/lutaml/json/adapter/oj_adapter.rb', line 11 def self.parse(json, = {}) require "oj" Oj.load(json) rescue LoadError raise LoadError, "oj gem is not available. Please add 'oj' to your Gemfile or use the StandardAdapter." end |
Instance Method Details
#ignores_generator_options? ⇒ Boolean
rubocop:disable Style/ArgumentsForwarding -- anonymous * requires Ruby 3.2+ Oj has its own option namespace and its own escape_mode. Handing it the stdlib generator's options overrides that configuration, so it takes none of them -- which is what it received before.
23 24 25 |
# File 'lib/lutaml/json/adapter/oj_adapter.rb', line 23 def true end |
#to_json(*args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lutaml/json/adapter/oj_adapter.rb', line 27 def to_json(*args) require "oj" # Handle KeyValueElement input (new symmetric architecture) attributes_to_serialize = if @attributes.is_a?(Lutaml::KeyValue::DataModel::Element) # Unwrap __root__ wrapper to get actual content @attributes.to_hash["__root__"] else # Legacy Hash input (backward compatibility) @attributes end Oj.dump(attributes_to_serialize, *args) # rubocop:enable Style/ArgumentsForwarding rescue LoadError raise LoadError, "oj gem is not available. Please add 'oj' to your Gemfile or use the StandardAdapter." end |