Sha256: 692a14ce054f0c314a7685e05250c3e1db6a21a1008a6b45f8160e9a9757949a

Contents?: true

Size: 601 Bytes

Versions: 4

Compression:

Stored size: 601 Bytes

Contents

require "json"

module Lutaml
  module Model
    module Type
      # JSON representation
      class Json
        attr_reader :value

        def initialize(value)
          @value = value
        end

        def to_json(*_args)
          @value.to_json
        end

        def ==(other)
          @value == (other.is_a?(::Hash) ? other : other.value)
        end

        def self.cast(value)
          return value if value.is_a?(self) || value.nil?

          new(::JSON.parse(value))
        end

        def self.serialize(value)
          value.to_json
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lutaml-model-0.3.5 lib/lutaml/model/type/json.rb
lutaml-model-0.3.4 lib/lutaml/model/type/json.rb
lutaml-model-0.3.3 lib/lutaml/model/type/json.rb
lutaml-model-0.3.2 lib/lutaml/model/type/json.rb