Sha256: 5e22b385188438e97a5e7fa78129dd859b26c790c71b1fd554ac619cd74aa89b

Contents?: true

Size: 1.48 KB

Versions: 15

Compression:

Stored size: 1.48 KB

Contents

module Oj
  # A SAX style parse handler for JSON hence the acronym SAJ for Simple API for JSON. The Oj::Saj handler class should be subclassed
  # and then used with the Oj.saj_parse() method. The Saj methods will then be
  # called as the file is parsed.
  # @example
  # 
  #  require 'oj'
  #
  #  class MySaj < ::Oj::Saj
  #    def initialize()
  #      @hash_cnt = 0
  #    end
  #
  #    def start_hash(key)
  #      @hash_cnt += 1
  #    end
  #  end
  #
  #  cnt = MySaj.new()
  #  File.open('any.xml', 'r') do |f|
  #    Oj.saj_parse(cnt, f)
  #  end
  #
  # To make the desired methods active while parsing the desired method should be made public in the subclasses. If the
  # methods remain private they will not be called during parsing.
  #
  #    def hash_start(key); end
  #    def hash_end(key); end
  #    def array_start(key); end
  #    def array_end(key); end
  #    def add_value(value, key); end
  #    def error(message, line, column); end
  #
  class Saj
    # Create a new instance of the Saj handler class.
    def initialize()
    end

    # To make the desired methods active while parsing the desired method
    # should be made public in the subclasses. If the methods remain private
    # they will not be called during parsing.
    private

    def hash_start(key)
    end

    def hash_end(key)
    end

    def array_start(key)
    end

    def array_end(key)
    end

    def add_value(value, key)
    end

    def error(message, line, column)
    end
    
  end # Saj
end # Oj

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
oj-2.0.14 lib/oj/saj.rb
oj-2.0.13 lib/oj/saj.rb
oj-2.0.12 lib/oj/saj.rb
oj-2.0.11 lib/oj/saj.rb
oj-2.0.10 lib/oj/saj.rb
oj-2.0.9 lib/oj/saj.rb
oj-2.0.8 lib/oj/saj.rb
oj-2.0.7 lib/oj/saj.rb
oj-2.0.6 lib/oj/saj.rb
oj-2.0.5 lib/oj/saj.rb
oj-2.0.4 lib/oj/saj.rb
oj-2.0.3 lib/oj/saj.rb
oj-2.0.2 lib/oj/saj.rb
oj-2.0.1 lib/oj/saj.rb
oj-2.0.0 lib/oj/saj.rb