diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b796c..5cb5463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ #### Fixes * Your contribution here. +* [#404](https://github.com/ruby-grape/grape-entity/pull/404): Drop `MultiJson` dependency, use `Hash#to_json` for ActiveSupport-aware serialization - [@numbata](https://github.com/numbata). ### 1.0.4 (2026-04-17) diff --git a/grape-entity.gemspec b/grape-entity.gemspec index 5b158df..b6b882b 100644 --- a/grape-entity.gemspec +++ b/grape-entity.gemspec @@ -25,7 +25,6 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0' s.add_dependency 'activesupport', '>= 3.0.0' - s.add_dependency 'multi_json', '>= 1.0' s.files = Dir['lib/**/*.rb', 'CHANGELOG.md', 'LICENSE', 'README.md'] s.require_paths = ['lib'] diff --git a/lib/grape_entity/entity.rb b/lib/grape_entity/entity.rb index cd14033..bd36d20 100644 --- a/lib/grape_entity/entity.rb +++ b/lib/grape_entity/entity.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'multi_json' - module Grape # An Entity is a lightweight structure that allows you to easily # represent data from your application in a consistent and abstracted @@ -594,7 +592,7 @@ def is_defined_in_entity?(attribute) def to_json(options = {}) options = options.to_h if options&.respond_to?(:to_h) - MultiJson.dump(serializable_hash(options)) + serializable_hash(options).to_json end def to_xml(options = {}) diff --git a/spec/grape_entity/entity_spec.rb b/spec/grape_entity/entity_spec.rb index 5bdd73e..3d8a74a 100644 --- a/spec/grape_entity/entity_spec.rb +++ b/spec/grape_entity/entity_spec.rb @@ -1886,7 +1886,7 @@ class NoPathCharacterEntity < Grape::Entity entity = fresh_class.new(model) json = entity.to_json parsed = JSON.parse(json) - expect(parsed['birthday']).to eq(attributes[:birthday].as_json) + expect(parsed['birthday']).to eq('2012-02-27T00:00:00.000Z') end it 'serializes Time values in nested exposures via as_json' do @@ -1895,7 +1895,7 @@ class NoPathCharacterEntity < Grape::Entity end entity = fresh_class.new(model) parsed = JSON.parse(entity.to_json) - expect(parsed['details']['birthday']).to eq(attributes[:birthday].as_json) + expect(parsed['details']['birthday']).to eq('2012-02-27T00:00:00.000Z') end end