diff --git a/frameworks/Ruby/hanami/app/actions/db/index.rb b/frameworks/Ruby/hanami/app/actions/db/index.rb index e5efcc2f414..3b67c404287 100644 --- a/frameworks/Ruby/hanami/app/actions/db/index.rb +++ b/frameworks/Ruby/hanami/app/actions/db/index.rb @@ -11,7 +11,7 @@ class Index < HelloWorld::Action def handle(*, response) world = world_repo.find(random_id) response.format = :json - response.body = world.to_h.to_json + response.body = JSON.generate(world.to_h) end def random_id diff --git a/frameworks/Ruby/hanami/app/actions/queries/index.rb b/frameworks/Ruby/hanami/app/actions/queries/index.rb index d20dfc2df3a..2dda18b8438 100644 --- a/frameworks/Ruby/hanami/app/actions/queries/index.rb +++ b/frameworks/Ruby/hanami/app/actions/queries/index.rb @@ -16,7 +16,7 @@ def handle(request, response) world_repo.find(id) end response.format = :json - response.body = worlds.map(&:to_h).to_json + response.body = JSON.generate(worlds.map(&:to_h)) end private diff --git a/frameworks/Ruby/hanami/app/actions/updates/index.rb b/frameworks/Ruby/hanami/app/actions/updates/index.rb index 3e68be733be..d31d18f3ab2 100644 --- a/frameworks/Ruby/hanami/app/actions/updates/index.rb +++ b/frameworks/Ruby/hanami/app/actions/updates/index.rb @@ -16,7 +16,7 @@ def handle(request, response) world_repo.update_random_number(id) end response.format = :json - response.body = worlds.to_json + response.body = JSON.generate(worlds) end private diff --git a/frameworks/Ruby/hanami/config/routes.rb b/frameworks/Ruby/hanami/config/routes.rb index b57e5af753f..e438a379241 100644 --- a/frameworks/Ruby/hanami/config/routes.rb +++ b/frameworks/Ruby/hanami/config/routes.rb @@ -9,7 +9,7 @@ class Routes < Hanami::Routes 'Content-Type' => 'application/json', 'Date' => Time.now.httpdate, }, - [{ 'message' => 'Hello, World!' }.to_json]] + [JSON.generate({ 'message' => 'Hello, World!' })]] end get "/db", to: "db.index" get "/queries", to: "queries.index" diff --git a/frameworks/Ruby/padrino/app/controllers.rb b/frameworks/Ruby/padrino/app/controllers.rb index 6f812537284..1084918cf16 100644 --- a/frameworks/Ruby/padrino/app/controllers.rb +++ b/frameworks/Ruby/padrino/app/controllers.rb @@ -8,14 +8,14 @@ end get '/json', :provides => [:json] do - {message: "Hello, World!"}.to_json + JSON.generate({message: "Hello, World!"}) end get '/db', :provides => [:json] do world = ActiveRecord::Base.with_connection do World.find(rand1).attributes end - world.to_json + JSON.generate(world) end get '/queries', :provides => [:json] do @@ -24,7 +24,7 @@ World.find(id).attributes end end - worlds.to_json + JSON.generate(worlds) end get '/fortunes' do @@ -51,7 +51,7 @@ World.upsert_all(worlds) end - worlds.to_json + JSON.generate(worlds) end get '/plaintext' do diff --git a/frameworks/Ruby/rack-app/app.rb b/frameworks/Ruby/rack-app/app.rb index af4b7d20b27..d08b21e02c8 100644 --- a/frameworks/Ruby/rack-app/app.rb +++ b/frameworks/Ruby/rack-app/app.rb @@ -35,22 +35,23 @@ def fortunes get '/json' do set_headers(JSON_TYPE) - { message: 'Hello, World!' }.to_json + JSON.generate({ message: 'Hello, World!' }) end get '/db' do set_headers(JSON_TYPE) - World.with_pk(rand1).values.to_json + JSON.generate(World.with_pk(rand1).values) end get '/queries' do set_headers(JSON_TYPE) ids = ALL_IDS.sample(bounded_queries) - DB.synchronize do + worlds = DB.synchronize do ids.map do |id| World.with_pk(id).values end - end.to_json + end + JSON.generate(worlds) end get '/fortunes' do diff --git a/frameworks/Ruby/rack-sequel/hello_world.rb b/frameworks/Ruby/rack-sequel/hello_world.rb index e1be4656bb7..27371b28f5e 100644 --- a/frameworks/Ruby/rack-sequel/hello_world.rb +++ b/frameworks/Ruby/rack-sequel/hello_world.rb @@ -105,19 +105,19 @@ def call(env) case env['PATH_INFO'] when '/json' # Test type 1: JSON serialization - respond JSON_TYPE, { message: 'Hello, World!' }.to_json + respond JSON_TYPE, JSON.generate({ message: 'Hello, World!' }) when '/db' # Test type 2: Single database query - respond JSON_TYPE, db.to_json + respond JSON_TYPE, JSON.generate(db) when '/queries' # Test type 3: Multiple database queries - respond JSON_TYPE, queries(env).to_json + respond JSON_TYPE, JSON.generate(queries(env)) when '/fortunes' # Test type 4: Fortunes respond HTML_TYPE, fortunes when '/updates' # Test type 5: Database updates - respond JSON_TYPE, updates(env).to_json + respond JSON_TYPE, JSON.generate(updates(env)) when '/plaintext' # Test type 6: Plaintext respond PLAINTEXT_TYPE, 'Hello, World!' diff --git a/frameworks/Ruby/rack/hello_world.rb b/frameworks/Ruby/rack/hello_world.rb index af768daa042..08afc15cd2e 100644 --- a/frameworks/Ruby/rack/hello_world.rb +++ b/frameworks/Ruby/rack/hello_world.rb @@ -53,22 +53,22 @@ def call(env) when '/json' # Test type 1: JSON serialization respond JSON_TYPE, - { message: 'Hello, World!' }.to_json + JSON.generate({ message: 'Hello, World!' }) when '/db' # Test type 2: Single database query id = random_id - respond JSON_TYPE, $db.with{ _1.select_world(id) }.to_json + respond JSON_TYPE, JSON.generate($db.with{ _1.select_world(id) }) when '/queries' # Test type 3: Multiple database queries queries = bounded_queries(env) - respond JSON_TYPE, select_worlds(queries).to_json + respond JSON_TYPE, JSON.generate(select_worlds(queries)) when '/fortunes' # Test type 4: Fortunes respond HTML_TYPE, fortunes when '/updates' # Test type 5: Database updates queries = bounded_queries(env) - respond JSON_TYPE, update_worlds(queries).to_json + respond JSON_TYPE, JSON.generate(update_worlds(queries)) when '/plaintext' # Test type 6: Plaintext respond PLAINTEXT_TYPE, 'Hello, World!' diff --git a/frameworks/Ruby/rails/config/routes.rb b/frameworks/Ruby/rails/config/routes.rb index 1987aabc219..2b310738b5b 100644 --- a/frameworks/Ruby/rails/config/routes.rb +++ b/frameworks/Ruby/rails/config/routes.rb @@ -9,7 +9,7 @@ 'Content-Type' => 'application/json', 'Date' => Time.now.httpdate, }, - [{ 'message' => 'Hello, World!' }.to_json]] + [JSON.generate({ 'message' => 'Hello, World!' })]] end else ->(env) do @@ -18,7 +18,7 @@ 'Server' => 'Rails', 'Content-Type' => 'application/json' }, - [{ 'message' => 'Hello, World!' }.to_json]] + [JSON.generate({ 'message' => 'Hello, World!' })]] end end diff --git a/frameworks/Ruby/roda-sequel/hello_world.rb b/frameworks/Ruby/roda-sequel/hello_world.rb index ec00dd518cf..42bf22c3afc 100644 --- a/frameworks/Ruby/roda-sequel/hello_world.rb +++ b/frameworks/Ruby/roda-sequel/hello_world.rb @@ -41,13 +41,13 @@ def rand1 # Test type 1: JSON serialization r.is "json" do response[CONTENT_TYPE] = JSON_TYPE - { message: "Hello, World!" }.to_json + JSON.generate({ message: "Hello, World!" }) end # Test type 2: Single database query r.is "db" do response[CONTENT_TYPE] = JSON_TYPE - World.with_pk(rand1).values.to_json + JSON.generate(World.with_pk(rand1).values) end # Test type 3: Multiple database queries @@ -60,7 +60,7 @@ def rand1 World.with_pk(id).values end end - worlds.to_json + JSON.generate(worlds) end # Test type 4: Fortunes @@ -93,7 +93,7 @@ def rand1 end World.batch_update(worlds) end - worlds.map!(&:values).to_json + JSON.generate(worlds.map!(&:values)) end # Test type 6: Plaintext diff --git a/frameworks/Ruby/sinatra-sequel/hello_world.rb b/frameworks/Ruby/sinatra-sequel/hello_world.rb index 7c06269d80a..3f08ab904a6 100644 --- a/frameworks/Ruby/sinatra-sequel/hello_world.rb +++ b/frameworks/Ruby/sinatra-sequel/hello_world.rb @@ -104,7 +104,7 @@ class HelloWorld < Sinatra::Base def render_json(data) add_headers content_type :json - data.to_json + JSON.generate(data) end def render_html(template) diff --git a/frameworks/Ruby/sinatra/hello_world.rb b/frameworks/Ruby/sinatra/hello_world.rb index 93ac441f0fe..41c5f7a9cae 100644 --- a/frameworks/Ruby/sinatra/hello_world.rb +++ b/frameworks/Ruby/sinatra/hello_world.rb @@ -109,7 +109,7 @@ class HelloWorld < Sinatra::Base def render_json(data) add_headers content_type :json - data.to_json + JSON.generate(data) end def render_html(template)