Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Fixes

* Your contribution here.
* [#405](https://github.com/ruby-grape/grape-entity/pull/405): Fix `Time` serialization regression by reverting #385 and restoring `MultiJson.dump` - [@numbata](https://github.com/numbata).
* [#402](https://github.com/ruby-grape/grape-entity/pull/402): Remove `Json::ParseError` assignment - [@olivier-thatch](https://github.com/olivier-thatch).

### 1.0.3 (2026-04-15)
Expand Down
1 change: 1 addition & 0 deletions grape-entity.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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']
Expand Down
4 changes: 2 additions & 2 deletions lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'grape_entity/json'
require 'multi_json'

module Grape
# An Entity is a lightweight structure that allows you to easily
Expand Down Expand Up @@ -594,7 +594,7 @@ def is_defined_in_entity?(attribute)

def to_json(options = {})
options = options.to_h if options&.respond_to?(:to_h)
Grape::Entity::Json.dump(serializable_hash(options))
MultiJson.dump(serializable_hash(options))
end

def to_xml(options = {})
Expand Down
7 changes: 0 additions & 7 deletions lib/grape_entity/json.rb

This file was deleted.

17 changes: 17 additions & 0 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,23 @@ class NoPathCharacterEntity < Grape::Entity
it 'returns a json' do
expect(fresh_class.new(model).to_json).to eq(JSON.generate(attributes.slice(:name)))
end

it 'serializes Time values via as_json' do
fresh_class.expose :birthday
entity = fresh_class.new(model)
json = entity.to_json
parsed = JSON.parse(json)
expect(parsed['birthday']).to eq(attributes[:birthday].as_json)
end

it 'serializes Time values in nested exposures via as_json' do
fresh_class.expose :details do
fresh_class.expose :birthday
end
entity = fresh_class.new(model)
parsed = JSON.parse(entity.to_json)
expect(parsed['details']['birthday']).to eq(attributes[:birthday].as_json)
end
end

describe '#inspect' do
Expand Down
7 changes: 0 additions & 7 deletions spec/grape_entity/json_spec.rb

This file was deleted.

Loading