New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make python name to JSON name attribute mapping via attribute_map
optional.
#58
Comments
Hi @milancermak . As you mentioned above, we use this We had to do this because the JSON keys cannot be directly specified as attribute names since they do not follow PEP8 standards. If we remove this, then using some magic method, we have to convert the attributes back to the specific key names. This will lead to performance issues when the skill has to return a Also, in cases when the skill developer attaches any additional attributes on any of the Do you think we can do something under |
Yes, I do. Here's a diff of the changes that could be done to the 103a104,108
> class_attribute_map = getattr(obj, 'attribute_map', {})
> class_attribute_map.update({k: k for k
> in obj.deserialized_types.keys()
> if k not in class_attribute_map})
>
105c110
< obj.attribute_map[attr]: getattr(obj, attr)
---
> class_attribute_map[attr]: getattr(obj, attr)
282,283c287
< if hasattr(obj_type, 'deserialized_types') and hasattr(
< obj_type, 'attribute_map'):
---
> if hasattr(obj_type, 'deserialized_types'):
289c293,296
< class_attribute_map = obj_type.attribute_map
---
> class_attribute_map = getattr(obj_type, 'attribute_map', {})
> class_attribute_map.update({k: k for k
> in obj_type.deserialized_types.keys()
> if k not in class_attribute_map}) I can send a PR if it helps. |
Thanks for the diff @milancermak . We will look into it and let you know. You can also contribute to the changes by submitting a PR. |
Hey @milancermak , do you have a PR that we can look at? |
There it is 👍 |
Closing this since the PR is merged. Will be updating the PR #60 once the changes are released to PyPI. Thanks @milancermak for getting this to our attention and raising the PR. |
I'm submitting a...
Expected Behavior
When serializing, use the python attribute name if not present in
attribute_map
.Current Behavior
If a name of a python attribute is the same as its name in the serialized object, it still needs to be present in the
attribute_map
.Possible Solution
I guess it's a one-line change in the Serializer? Sorry, didn't dig into it too much.
Steps to Reproduce (for bugs)
Context
I'm using the
DefaultSerializer
to serialize my models for DynamoDB. It's really cool. I want to suggest of using the python's attribute name as the name of the value in the serialized object if it is not present in theattribute_map
mapping. In the example posted above, theattribute_map
could be removed altogether, a pattern in a lot of my models. This direct mapping is also quite common in the SDK models, for example here inSimpleCard
Your Environment
Python version info
The text was updated successfully, but these errors were encountered: