Sha256: 5876b1a2df6c750f467679ae846feabc5a3354b9d4344f03af13e4adfc2cdd4d

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

#!/usr/bin/env ruby

$: << '.'
$: << '../lib'
$: << '../ext'

require 'active_support'
require 'active_support/core_ext'
require 'active_support/json/encoding.rb'
require 'json'

class Foo
  def to_json(*)
    '{"foo":"bar"}'
  end
end

class Dub
  def initialize(a,b)
    @a = a
    @b = b
  end
end

puts "*** time respond to: #{Time.now.utc.respond_to?(:to_json)}"

hash_with_time = { foo: Time.now.utc }
boo = { boo: Time.now.utc, foo: Foo.new, dub: Dub.new(1,2) }
aaa = [Time.now.utc, Foo.new, Dub.new(1,2)]

puts "*** boo #{JSON.generate(boo)}"
puts "*** aaa #{JSON.generate(aaa)}"

puts "*** time: #{Time.now.utc.to_json}"

puts hash_with_time.to_json
# => {"foo":"2018-06-28T09:07:40.464Z"}
puts JSON.generate(hash_with_time)
# => {"foo":"2018-06-28 09:07:40 UTC"}


puts JSON.generate({ foo: Foo.new }.with_indifferent_access)
puts JSON.generate({ foo: Foo.new })
# => {"foo":{"foo":"bar"}}
puts({ foo: Foo.new }.to_json)
# => {"foo":{}}

puts "-------------------"
require 'oj'

#Oj.optimize_rails
Oj.mimic_JSON

puts "*** boo #{JSON.generate(boo)}"

Oj.default_options = {trace: true}
puts hash_with_time.to_json
# => {"foo":"2018-06-28T09:07:40.464Z"}
puts JSON.generate(hash_with_time)
# => {"foo":"2018-06-28T09:07:40.464Z"}
puts hash_with_time.to_json

puts JSON.generate({ foo: Foo.new }.with_indifferent_access)
puts JSON.generate({ foo: Foo.new })
# => {"foo":{}}
puts({ foo: Foo.new }.to_json)
# => {"foo":{}}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oj-3.6.4 test/foo.rb