Skip to content
Open
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 lib/temporal/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Temporal
module JSON
OJ_OPTIONS = {
mode: :object,
circular: true,
# use ruby's built-in serialization. If nil, OJ seems to default to ~15 decimal places of precision
float_precision: 0
}.freeze
Expand Down
5 changes: 2 additions & 3 deletions spec/unit/lib/temporal/connection/serializer/failure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize(message)
expect(avoids_truncation_error).to eq(old_style_deserialized_error)
end

it 'logs a helpful error when the payload is too large' do
it 'logs a helpful error when the payload is too large' do
e = MyBigError.new('Uh oh!')

allow(Temporal.logger).to receive(:error)
Expand All @@ -90,10 +90,9 @@ def initialize(message)
.to have_received(:error)
.with(
"Could not serialize exception because it's too large, so we are using a fallback that may not deserialize "\
"correctly on the client. First #{max_bytes} bytes:\n{\"^o\":\"MyBigError\",\"big_payload\":\"1234567890123456",
"correctly on the client. First #{max_bytes} bytes:\n{\"^o\":\"MyBigError\",\"^i\":1,\"big_payload\":\"123456789",
{ unserializable_error: 'MyBigError' }
)

end

class MyArglessError < RuntimeError
Expand Down
15 changes: 14 additions & 1 deletion spec/unit/lib/temporal/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

describe Temporal::JSON do
let(:hash) { { 'one' => 'one', two: :two, ':three' => ':three' } }
let(:json) { '{"one":"one",":two":":two","\u003athree":"\u003athree"}' }
let(:json) { '{"^i":1,"one":"one",":two":":two","\u003athree":"\u003athree"}' }

describe '.serialize' do
it 'generates JSON string' do
expect(described_class.serialize(hash)).to eq(json)
end

it 'does not raise error on circular entries' do
author = Struct.new('Author', :name, :books)
book = Struct.new('Book', :author)
author_entry = author.new(name: 'David')
book_entry = book.new(title: 'test', author: author)

author_entry.books = [book_entry]
json = described_class.serialize(author_entry)

result = described_class.deserialize(json)
expect(result).to eq(author_entry)
end
end

describe '.deserialize' do
Expand Down