Description
Use case
In some event classes (such as SQS, Kafka, and others), certain string fields (such as body) can be converted to JSON using the json.loads function. However, it is possible that the customer may have created the message with a JSON serialization method that differs from the default json class. To cover these scenarios, we need to provide customers with the flexibility to use a custom deserialization function of their choice.
This is important because by allowing customers to use their preferred deserialization function, we can ensure that their messages are properly deserialized into the intended format.
The default if nothing is informed will continue to be json.loads
Solution/User Experience
To address the issue, we can modify the DictWrapper class to introduce a new parameter. This parameter would allow customers to provide their preferred deserialization function for converting string fields to JSON.
class DictWrapper(Mapping):
"""Provides a single read only access to a wrapper dict"""
def __init__(self, data: Dict[str, Any], json_deserializer: Optional[Callable] = None):
self._data = data
self._json_data: Optional[Any] = None
self._json_deserializer = json_deserializer or json.loadsAlternative solutions
No response
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript, and .NET
Activity
github-actions commentedon May 4, 2023
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
github-actions commentedon May 4, 2023
This is now released under 2.15.0 version!
facu-01 commentedon Mar 21, 2024
How this can be used in APIGatewayRestResolver? i cant find the way to inject the custom json_deserializer.
if a make a post with json :
The last zero is removed, this issue could be solved using
json.loads(parse_float=Decimal)