You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, is it possible to make this optional? I went to upgrade this dependency in a project that relies on the json output having different key names and afaict it's not possible to make it output `var.name` instead of `var.local_name` without just copying next_value and changing that yield.
Hi @delfick iat that time I was using the json bindings for tests mostly, it doesn't make sense to add an option to override the qualified name. It's pretty easy to override the JsonSerializer to achieve this.
# TODO: Hopefully future version of xsdata makes the key behaviour configurable
class ModifiedJsonSerializer(serializers.JsonSerializer):
def next_value(self, obj: t.Any) -> t.Iterator[t.Tuple[str, t.Any]]:
"""
Exactly the same as is in serializers.JsonSerializer accept we yield var.name
instead of var.local_name
https://github.com/tefra/xsdata/issues/389#issuecomment-1305216183
"""
ignore_optionals = self.config.ignore_default_attributes
for var in self.context.build(obj.__class__).get_all_vars():
value = getattr(obj, var.name)
if var.is_attribute and ignore_optionals and var.is_optional(value):
continue
yield var.name, self.convert(value, var)
and surely this is exactly the kind of thing the config class is for?
Specifically here, https://github.com/tefra/xsdata/blob/v22.11/xsdata/formats/dataclass/serializers/json.py#L104
Originally posted by @delfick in #389 (comment)
The text was updated successfully, but these errors were encountered: