lib/lutaml/model/serialize.rb in lutaml-model-0.3.19 vs lib/lutaml/model/serialize.rb in lutaml-model-0.3.20

- old
+ new

@@ -330,11 +330,13 @@ defaults_used = [] mappings.each do |rule| raise "Attribute '#{rule.to}' not found in #{self}" unless valid_rule?(rule) - value = if rule.content_mapping? + value = if rule.raw_mapping? + doc.node.inner_xml + elsif rule.content_mapping? doc["text"] elsif doc.key_exist?(rule.namespaced_name) doc.fetch(rule.namespaced_name) else defaults_used << rule.to @@ -395,19 +397,24 @@ value["text"] else value end - if attr && !rule.content_mapping? && !rule.custom_methods[:from] - value = attr.cast( - value, - :xml, - caller_class: self, - mixed_content: rule.mixed_content, - ) - end + return value unless cast_value?(attr, rule) - value + attr.cast( + value, + :xml, + caller_class: self, + mixed_content: rule.mixed_content, + ) + end + + def cast_value?(attr, rule) + attr && + !rule.raw_mapping? && + !rule.content_mapping? && + !rule.custom_methods[:from] end def text_hash?(attr, value) return false unless value.is_a?(Hash) return value.keys == ["text"] unless attr