This repository was archived by the owner on Jul 28, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +48
-5
lines changed
Expand file tree Collapse file tree 3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( http://keepachangelog.com/en/1.0.0/ )
55and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
66
7+ ## [ Unreleased]
8+
9+ ### Changes
10+ - Fix symbol json encoding breaking compatibility with some gems
11+
712## [ 0.4.0] - 2019-03-25
813### Added
914- Calling ` #dispatch ` on tasks now allows to process tasks asynchronously
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33require 'singleton'
4- require 'json/add/core'
4+ require 'json/add/date'
5+ require 'json/add/date_time'
6+ require 'json/add/exception'
7+ require 'json/add/range'
8+ require 'json/add/regexp'
9+ require 'json/add/struct'
10+ require 'json/add/time'
511require 'json/add/rational'
612require 'json/add/complex'
713require 'json/add/bigdecimal'
@@ -97,14 +103,22 @@ def valid_object(object, super_class)
97103 end
98104
99105 def from_complex_type ( object )
100- JSON . parse ( object . to_json ) . tap do |attributes |
101- attributes . delete ( 'json_class' )
106+ if object . is_a? ( Symbol )
107+ { 's' => object . to_s }
108+ else
109+ JSON . parse ( object . to_json ) . tap do |attributes |
110+ attributes . delete ( 'json_class' )
111+ end
102112 end
103113 end
104114
105115 def set_complex_type ( object , props )
106- props [ 'json_class' ] = object . class . name
107- JSON ( props . to_json )
116+ if object . is_a? ( Symbol )
117+ props [ 's' ] . to_sym
118+ else
119+ props [ 'json_class' ] = object . class . name
120+ JSON ( props . to_json )
121+ end
108122 end
109123
110124 def special_case? ( object )
Original file line number Diff line number Diff line change 1919 end
2020 end
2121
22+ context 'with a symbol' do
23+ let ( :data ) { :foobar }
24+
25+ it 'represents the symbol as a data' do
26+ expect ( parsed_json ) . to eq (
27+ 'o' => '@zenaton#0' ,
28+ 's' => [ { 'n' => 'Symbol' , 'p' => { 's' => 'foobar' } } ]
29+ )
30+ end
31+ end
32+
2233 context 'with an integer' do
2334 let ( :data ) { 1 }
2435
325336 end
326337 end
327338
339+ context 'with a symbol do' do
340+ let ( :json ) do
341+ {
342+ 'o' => '@zenaton#0' ,
343+ 's' => [ { 'n' => 'Symbol' , 'p' => { 's' => 'foobar' } } ]
344+ } . to_json
345+ end
346+
347+ it 'returns the symbol' do
348+ expect ( decoded ) . to eq ( :foobar )
349+ end
350+ end
351+
328352 context 'with an integer do' do
329353 let ( :json ) { { 'd' => 1 , 's' => [ ] } . to_json }
330354
You can’t perform that action at this time.
0 commit comments