Class: Lutaml::Json::Adapter::StandardAdapter
- Inherits:
-
Document
- Object
- KeyValue::Document
- Document
- Lutaml::Json::Adapter::StandardAdapter
- Defined in:
- lib/lutaml/json/adapter/standard_adapter.rb
Direct Known Subclasses
Constant Summary collapse
- FORMAT_SYMBOL =
:json
Instance Attribute Summary
Attributes inherited from KeyValue::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 KeyValue::Document
#[], #[]=, #initialize, #key?, #to_h
Constructor Details
This class inherits a constructor from Lutaml::KeyValue::Document
Class Method Details
.parse(json, _options = {}) ⇒ Object
13 14 15 |
# File 'lib/lutaml/json/adapter/standard_adapter.rb', line 13 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.
19 20 21 |
# File 'lib/lutaml/json/adapter/standard_adapter.rb', line 19 def accepts_generator_state? true end |
#to_json(*args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lutaml/json/adapter/standard_adapter.rb', line 23 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 GeneratorOptions.(args.first) return JSON.generate(attributes_to_serialize, args.first) end = args.first || {} = GeneratorOptions.filter() if [:pretty] JSON.pretty_generate(attributes_to_serialize, ) else JSON.generate(attributes_to_serialize, ) end end |