Skip to content

Commit

Permalink
use custom/compact JSON create_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorino committed Oct 8, 2024
1 parent 558888c commit 3332b2a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/firm/serializer/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module Serializable

module JSON

CREATE_ID = 'rbklass'.freeze

# Derived Hash class to use for deserialized JSON object data which
# supports using Symbol keys.
class ObjectHash < ::Hash
Expand Down Expand Up @@ -162,6 +164,8 @@ def self.dump(obj, io=nil, pretty: false)
begin
# initialize anchor registry
Serializable::Aliasing.start_anchor_object_registry
# set custom (more compact) create_id
::JSON.create_id = Serializable::JSON::CREATE_ID
for_json = obj.respond_to?(:as_json) ? obj.as_json : obj
if pretty
if io || io.respond_to?(:write)
Expand All @@ -185,6 +189,8 @@ def self.load(source)
Serializable::Aliasing.start_anchor_references
# enable safe deserializing
self.start_safe_deserialize
# set custom (more compact) create_id
::JSON.create_id = Serializable::JSON::CREATE_ID
::JSON.parse!(source,
create_additions: true,
object_class: Serializable::JSON::ObjectHash)
Expand Down

0 comments on commit 3332b2a

Please sign in to comment.