Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Jul 6, 2024
1 parent 48208aa commit c24472b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions serializable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ def as_xml(self: Any, view_: Optional[Type[ViewType]] = None,
SubElement(this_e, new_key).text = _xs_string_mod_apply(str(prop_info.custom_type(v)),
prop_info.xml_string_config)
elif prop_info.is_enum:
SubElement(this_e, new_key).text = _xs_string_mod_apply(str(v.value), prop_info.xml_string_config)
SubElement(this_e, new_key).text = _xs_string_mod_apply(str(v.value),
prop_info.xml_string_config)
elif not prop_info.is_primitive_type():
global_klass_name = f'{prop_info.concrete_type.__module__}.{prop_info.concrete_type.__name__}'
if global_klass_name in ObjectMetadataLibrary.klass_mappings:
Expand All @@ -519,16 +520,19 @@ def as_xml(self: Any, view_: Optional[Type[ViewType]] = None,
else:
# Handle properties that have a type that is not a Python Primitive (e.g. int, float, str)
if prop_info.string_format:
SubElement(this_e, new_key).text = f'{v:{prop_info.string_format}}'
SubElement(this_e, new_key).text = _xs_string_mod_apply(f'{v:{prop_info.string_format}}',
prop_info.xml_string_config)
else:
SubElement(this_e, new_key).text = str(v)
SubElement(this_e, new_key).text = _xs_string_mod_apply(str(v),
prop_info.xml_string_config)
elif prop_info.concrete_type in (float, int):
SubElement(this_e, new_key).text = str(v)
elif prop_info.concrete_type is bool:
SubElement(this_e, new_key).text = str(v).lower()
else:
# Assume type is str
SubElement(this_e, new_key).text = _xs_string_mod_apply(str(v), prop_info.xml_string_config)
SubElement(this_e, new_key).text = _xs_string_mod_apply(str(v),
prop_info.xml_string_config)

if as_string:
return cast(Element, SafeElementTree.tostring(this_e, 'unicode'))
Expand Down

0 comments on commit c24472b

Please sign in to comment.