Class: Lutaml::Json::Adapter::StandardAdapter

Inherits:
Document show all
Defined in:
lib/lutaml/json/adapter/standard_adapter.rb

Constant Summary collapse

FORMAT_SYMBOL =
:json

Instance Attribute Summary

Attributes inherited from KeyValue::Document

#attributes, #register

Class Method Summary collapse

Instance Method Summary collapse

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
# File 'lib/lutaml/json/adapter/standard_adapter.rb', line 11

def self.parse(json, _options = {})
  JSON.parse(json, create_additions: false)
end

Instance Method Details

#to_json(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lutaml/json/adapter/standard_adapter.rb', line 15

def to_json(*args)
  options = args.first || {}

  # 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

  if options[:pretty]
    JSON.pretty_generate(attributes_to_serialize, *args)
  else
    JSON.generate(attributes_to_serialize, *args)
  end
end