diff --git a/lib/rdf/model/uri.rb b/lib/rdf/model/uri.rb index b2d5a360..c10523e6 100644 --- a/lib/rdf/model/uri.rb +++ b/lib/rdf/model/uri.rb @@ -1263,6 +1263,26 @@ def request_uri return res end + ## + # Dump of data needed to reconsitute this object using Marshal.load + # This override is needed to avoid serializing @mutex. + # + # @param [Integer] level The maximum depth of objects to dump. + # @return [String] The dump of data needed to reconsitute this object. + def _dump(level) + value + end + + ## + # Load dumped data to reconsitute marshaled object + # This override is needed to avoid serializing @mutex. + # + # @param [String] data The dump of data needed to reconsitute this object. + # @return [RDF::URI] The reconsituted object. + def self._load(data) + new(data) + end + private ## diff --git a/spec/model_uri_spec.rb b/spec/model_uri_spec.rb index 4769a2c0..19ac5ee7 100644 --- a/spec/model_uri_spec.rb +++ b/spec/model_uri_spec.rb @@ -983,4 +983,17 @@ end end end + + describe 'marshaling' do + subject { RDF::URI("http://example/") } + + it "marshals them" do + marshaled = Marshal.dump(subject) + loaded = Marshal.load(marshaled) + + expect(loaded).to eq subject + # It should have a mutex + expect { loaded.freeze }.not_to raise_error + end + end end