lib/lutaml/model/attribute.rb in lutaml-model-0.3.6 vs lib/lutaml/model/attribute.rb in lutaml-model-0.3.7

- old
+ new

@@ -38,8 +38,35 @@ end def render_nil? options.fetch(:render_nil, false) end + + def serialize(value, format, options = {}) + if value.is_a?(Array) + value.map do |v| + serialize(v, format, options) + end + elsif type <= Serialize + type.hash_representation(value, format, options) + else + type.serialize(value) + end + end + + def cast(value, format, options = {}) + value ||= [] if collection? + instance = options[:instance] + + if value.is_a?(Array) + value.map do |v| + cast(v, format, instance: instance) + end + elsif type <= Serialize + type.apply_mappings(value, format, options) + else + Lutaml::Model::Type.cast(value, type) + end + end end end end