module OandaAPI::Streaming::Adapters::Gson

Can be used if the ruby engine (`RUBY_ENGINE`) is jruby. Uses the {github.com/avsej/gson.rb gson} gem. Handles streams of multiple JSON objects that may or may not be delimited with whitespace.

Public Instance Methods

parse(string) click to toggle source

Deserializes a stream of JSON objects. @param [String] string serialized json. @return [Array<Hash>] an array of hashes.

# File lib/oanda_api/streaming/adapters/gson.rb, line 15
def parse(string)
  string.strip!
  return [] if string.empty?
  [parser.decode(string)].flatten
end

Private Instance Methods

parser() click to toggle source

@private Memoized parser instance.

# File lib/oanda_api/streaming/adapters/gson.rb, line 25
def parser
  @parser ||= ::Gson::Decoder.new(symbolize_keys: true)
end