oj 2.18.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -226
- data/ext/oj/circarray.c +0 -25
- data/ext/oj/circarray.h +0 -25
- data/ext/oj/code.c +227 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +126 -38
- data/ext/oj/custom.c +1097 -0
- data/ext/oj/dump.c +658 -2376
- data/ext/oj/dump.h +92 -0
- data/ext/oj/dump_compat.c +937 -0
- data/ext/oj/dump_leaf.c +254 -0
- data/ext/oj/dump_object.c +810 -0
- data/ext/oj/dump_rails.c +329 -0
- data/ext/oj/dump_strict.c +416 -0
- data/ext/oj/err.c +0 -25
- data/ext/oj/err.h +8 -2
- data/ext/oj/fast.c +24 -24
- data/ext/oj/mimic_json.c +817 -0
- data/ext/oj/mimic_rails.c +806 -0
- data/ext/oj/mimic_rails.h +17 -0
- data/ext/oj/object.c +18 -72
- data/ext/oj/odd.c +0 -25
- data/ext/oj/odd.h +2 -27
- data/ext/oj/oj.c +655 -1503
- data/ext/oj/oj.h +93 -40
- data/ext/oj/parse.c +99 -46
- data/ext/oj/parse.h +12 -26
- data/ext/oj/reader.c +1 -25
- data/ext/oj/reader.h +3 -25
- data/ext/oj/resolve.c +9 -11
- data/ext/oj/resolve.h +2 -2
- data/ext/oj/rxclass.c +133 -0
- data/ext/oj/rxclass.h +27 -0
- data/ext/oj/saj.c +4 -25
- data/ext/oj/scp.c +3 -25
- data/ext/oj/sparse.c +89 -13
- data/ext/oj/stream_writer.c +301 -0
- data/ext/oj/strict.c +4 -27
- data/ext/oj/string_writer.c +480 -0
- data/ext/oj/val_stack.h +6 -2
- data/lib/oj.rb +1 -23
- data/lib/oj/easy_hash.rb +12 -4
- data/lib/oj/json.rb +172 -0
- data/lib/oj/mimic.rb +123 -18
- data/lib/oj/state.rb +131 -0
- data/lib/oj/version.rb +1 -1
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/JsonGem.md +79 -0
- data/pages/Modes.md +140 -0
- data/pages/Options.md +250 -0
- data/pages/Rails.md +60 -0
- data/pages/Security.md +20 -0
- data/test/activesupport4/decoding_test.rb +105 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/decoding_test.rb +125 -0
- data/test/activesupport5/encoding_test.rb +483 -0
- data/test/activesupport5/encoding_test_cases.rb +90 -0
- data/test/activesupport5/test_helper.rb +50 -0
- data/test/activesupport5/time_zone_test_helpers.rb +24 -0
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +143 -0
- data/test/json_gem/json_encoding_test.rb +109 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +383 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +18 -0
- data/test/perf_compat.rb +30 -28
- data/test/perf_object.rb +1 -1
- data/test/perf_strict.rb +18 -1
- data/test/sample.rb +0 -1
- data/test/test_compat.rb +169 -93
- data/test/test_custom.rb +355 -0
- data/test/test_file.rb +0 -8
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +268 -3
- data/test/test_scp.rb +22 -1
- data/test/test_strict.rb +160 -4
- data/test/test_various.rb +52 -620
- data/test/tests.rb +14 -0
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- metadata +89 -47
- data/test/activesupport_datetime_test.rb +0 -23
- data/test/bug.rb +0 -51
- data/test/bug2.rb +0 -10
- data/test/bug3.rb +0 -46
- data/test/bug_fast.rb +0 -32
- data/test/bug_load.rb +0 -24
- data/test/crash.rb +0 -111
- data/test/curl/curl_oj.rb +0 -46
- data/test/curl/get_oj.rb +0 -24
- data/test/curl/just_curl.rb +0 -31
- data/test/curl/just_oj.rb +0 -51
- data/test/example.rb +0 -11
- data/test/foo.rb +0 -24
- data/test/io.rb +0 -48
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/mod.rb +0 -16
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/struct.rb +0 -29
- data/test/test_serializer.rb +0 -59
- data/test/write_timebars.rb +0 -31
data/test/rails.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$VERBOSE = true
|
5
|
-
|
6
|
-
here = File.expand_path(File.dirname(__FILE__))
|
7
|
-
$: << File.dirname(__FILE__)
|
8
|
-
$: << File.join(File.dirname(here), 'ext')
|
9
|
-
$: << File.join(File.dirname(here), 'lib')
|
10
|
-
|
11
|
-
require "active_record"
|
12
|
-
require "minitest/autorun"
|
13
|
-
require "logger"
|
14
|
-
require 'sidekiq/testing'
|
15
|
-
require "rspec/mocks/minitest_integration"
|
16
|
-
require 'oj'
|
17
|
-
|
18
|
-
Oj.mimic_JSON
|
19
|
-
|
20
|
-
Sidekiq::Testing.inline!
|
21
|
-
|
22
|
-
# Ensure backward compatibility with Minitest 4
|
23
|
-
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
24
|
-
|
25
|
-
# This connection will do for database-independent bug reports.
|
26
|
-
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
27
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
28
|
-
|
29
|
-
ActiveRecord::Schema.define do
|
30
|
-
create_table :posts, force: true do |t|
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Post < ActiveRecord::Base
|
35
|
-
end
|
36
|
-
|
37
|
-
class MyWorker
|
38
|
-
include Sidekiq::Worker
|
39
|
-
|
40
|
-
def perform(post)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class BugTest < Minitest::Test
|
45
|
-
def test_as_json
|
46
|
-
Post.arel_table
|
47
|
-
dbl = instance_double("Post", id: 1)
|
48
|
-
MyWorker.perform_async dbl
|
49
|
-
end
|
50
|
-
end
|
data/test/russian.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
%w(lib ext test).each do |dir|
|
7
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'oj'
|
11
|
-
|
12
|
-
s = %|{"response":[{"id":7250,"from_id":1382722,"owner_id":1382722,"date":1415964230,"post_type":"post","text":"Сдается комната в 2-х комнатной квартире с декабря месяца в Люберцах. (р-он Красная Горка)\nСдается желательно семейной паре (можно рассмотреть и другие варианты). \nв комнате одна большая . Стол, Шкаф, комод.\nДля проживания все есть. в Соседней комнате проживают два парня (из Чувашии)\nДо города можно доехать на маршрутке (20 мин.) на против дома остановка, на электричке (до электрички 15-20 мин. пешком) или на автобусе\nЦена 15 тыс. за комнату + коммунальные услуги\nЗвоните 8\/903\/012-34-25 венера","comments":{"count":0},"likes":{"count":1},"reposts":{"count":0}}]}|
|
13
|
-
|
14
|
-
r = Oj.load(s)
|
15
|
-
|
16
|
-
text = r["response"][0]["text"]
|
17
|
-
puts "#{text}"
|
18
|
-
puts "#{text.encoding}"
|
data/test/struct.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
|
5
|
-
# required. That can be set in the RUBYOPT environment variable.
|
6
|
-
# export RUBYOPT=-w
|
7
|
-
|
8
|
-
$VERBOSE = true
|
9
|
-
|
10
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
11
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
12
|
-
|
13
|
-
require 'oj'
|
14
|
-
|
15
|
-
A = Struct.new(:a,:b,:c,:d)
|
16
|
-
B = Struct.new(:e,:f)
|
17
|
-
|
18
|
-
obj = [A.new(55, B.new(1, 'X'), B.new(2, 'Y'), 3)]
|
19
|
-
|
20
|
-
s = Oj.dump(obj, :mode => :object)
|
21
|
-
|
22
|
-
100000.times do
|
23
|
-
Oj.load(s, :mode => :object)
|
24
|
-
# ds = Oj.dump(o, :mode => :object)
|
25
|
-
# if ds != s
|
26
|
-
# puts ds
|
27
|
-
# raise "holy crap"
|
28
|
-
# end
|
29
|
-
end
|
data/test/test_serializer.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
%w(lib ext test).each do |dir|
|
7
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'minitest'
|
11
|
-
require 'minitest/autorun'
|
12
|
-
require 'oj'
|
13
|
-
|
14
|
-
Oj.mimic_JSON
|
15
|
-
|
16
|
-
require 'rails/all'
|
17
|
-
require 'active_model'
|
18
|
-
require 'active_model_serializers'
|
19
|
-
require 'active_support/json'
|
20
|
-
|
21
|
-
#Oj.mimic_JSON
|
22
|
-
|
23
|
-
class Category
|
24
|
-
include ActiveModel::Model
|
25
|
-
include ActiveModel::SerializerSupport
|
26
|
-
|
27
|
-
attr_accessor :id, :name
|
28
|
-
|
29
|
-
def initialize(id, name)
|
30
|
-
@id = id
|
31
|
-
@name = name
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class CategorySerializer < ActiveModel::Serializer
|
36
|
-
attributes :id, :name
|
37
|
-
end
|
38
|
-
|
39
|
-
class MimicRails < Minitest::Test
|
40
|
-
|
41
|
-
def test_dump_object
|
42
|
-
Oj.default_options= {:indent => 0}
|
43
|
-
category = Category.new(1, 'test')
|
44
|
-
serializer = CategorySerializer.new(category)
|
45
|
-
|
46
|
-
json = serializer.to_json()
|
47
|
-
puts "*** serializer.to_json() #{serializer.to_json()}"
|
48
|
-
assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
|
49
|
-
|
50
|
-
json = serializer.as_json()
|
51
|
-
puts "*** serializer.as_json() #{serializer.as_json()}"
|
52
|
-
assert_equal({"category" => {:id => 1, :name => "test"}}, json)
|
53
|
-
|
54
|
-
json = JSON.dump(serializer)
|
55
|
-
puts "*** JSON.dump(serializer) #{JSON.dump(serializer)}"
|
56
|
-
assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
|
57
|
-
end
|
58
|
-
|
59
|
-
end # MimicRails
|
data/test/write_timebars.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
%w(lib ext).each do |dir|
|
5
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'stringio'
|
9
|
-
require 'oj'
|
10
|
-
|
11
|
-
|
12
|
-
filename = File.join(File.dirname(__FILE__), 'day.json')
|
13
|
-
File.open(filename, "w") do |f|
|
14
|
-
w = Oj::StreamWriter.new(f, :indent => -1)
|
15
|
-
390.times do |i|
|
16
|
-
w.push_object()
|
17
|
-
w.push_value(12, 'msgType')
|
18
|
-
w.push_value(1, 'version')
|
19
|
-
w.push_value(1_400_074_200 + i * 60, 'bar')
|
20
|
-
w.push_value('TBC', 'source')
|
21
|
-
w.push_array('timebars')
|
22
|
-
w.push_object()
|
23
|
-
w.push_value('aapl_24', 'asset')
|
24
|
-
w.push_value(91.87, 'close')
|
25
|
-
w.pop()
|
26
|
-
w.pop()
|
27
|
-
w.pop()
|
28
|
-
end
|
29
|
-
f.write("\n")
|
30
|
-
end
|
31
|
-
|