Serialization/Deserialization ruby object in YAML -
i'm trying understand serialization/deserialization of ruby object using yaml under 1.8.7 , 1.9+ , have few queries regarding (i can't find documentation on this)
ruby 1.8.7
class element yaml_as "tag:ruby.yaml.org,2002:element" def self.yaml_new(klass, tag, val) puts "print in yaml" end end yaml.parser => syck ## parser set syck e = element.new.to_yaml => "--- !ruby/element {}\n\n"
question 1: why didn't tag:ruby.yaml.org,2002:element
instead of --- !ruby/element {}\n\n
?
yaml.load(e) => print in "yaml" ##print statement execute ## not sure change parser in 1.8 `pysch` skipping part
ruby 1.9+
yaml::engine.yamler => pysch e = element.new.to_yaml => "--- !<tag:ruby.yaml.org,2002:element> {}\n" ## see tag in 1.9+ fine
question 2 : why working in 1.9+ , not in 1.8.7 ?
yaml.load(e) => ## print not getting printed
question 3: why print in yaml
isn't getting printed? in other words, why self.yaml_new
not getting invoked on yaml.load
? not supported under 1.9+ ?
yaml::engine.yamler = 'syck' => syck u = element.new.to_yaml => "--- !ruby/object:element {}\n\n"
question 4 (similar question #1) : why the tag(tag:ruby.yaml.org,2002:element
) missing in serialize
yaml above
yaml.load(e) => ## suprisingly, print not executed
question 5 (similar question #2): why isn't self.yaml_new
getting executed syck , pysch parser in ruby 1.9+ ?
can can me resolve these questions?
- question 1: don't have answer one
- question 2: because psych handles correctly should use
yaml_tag
instead ofyaml_tag
- question 3: use
def yaml_initialize(tag, val)
, work - question 4: because it's syck again, behaves in ruby 1.8
- question 5: same q4
Comments
Post a Comment