Class: Lutaml::KeyValue::Adapter::Json::StandardAdapter
Constant Summary collapse
- FORMAT_SYMBOL =
:json
Instance Attribute Summary
Attributes inherited from Document
Class Method Summary collapse
Instance Method Summary collapse
-
#accepts_generator_state? ⇒ Boolean
This adapter hands its payload to the stdlib generator, so a JSON::State carrying the outer formatting is meaningful here.
- #to_json(*args) ⇒ Object
Methods inherited from Document
#[], #[]=, #initialize, #key?, #to_h
Constructor Details
This class inherits a constructor from Lutaml::KeyValue::Document
Class Method Details
.parse(json, _options = {}) ⇒ Object
16 17 18 |
# File 'lib/lutaml/key_value/adapter/json/standard_adapter.rb', line 16 def self.parse(json, = {}) JSON.parse(json) end |
Instance Method Details
#accepts_generator_state? ⇒ Boolean
This adapter hands its payload to the stdlib generator, so a JSON::State carrying the outer formatting is meaningful here.
22 23 24 |
# File 'lib/lutaml/key_value/adapter/json/standard_adapter.rb', line 22 def accepts_generator_state? true end |
#to_json(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lutaml/key_value/adapter/json/standard_adapter.rb', line 26 def to_json(*args) # 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 unless Lutaml::Json::GeneratorOptions.(args.first) return JSON.generate(attributes_to_serialize, args.first) end = args.first || {} = Lutaml::Json::GeneratorOptions.filter() if [:pretty] JSON.pretty_generate(attributes_to_serialize, ) else JSON.generate(attributes_to_serialize, ) end end |