-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
Add DynamicObjects::try_parse
for typed object conversion
#1061
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great. thanks a lot. minor nits on error type only.
DynamicObjects::try_parse
for dyn -> typed object conversion
DynamicObjects::try_parse
for dyn -> typed object conversionDynamicObjects::try_parse
for typed object conversion
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1061 +/- ##
==========================================
+ Coverage 72.32% 72.36% +0.04%
==========================================
Files 65 65
Lines 4704 4712 +8
==========================================
+ Hits 3402 3410 +8
Misses 1302 1302
|
Issue: kube-rs#1029 To avoid manually parsing DynamicObjects into resources, this commit implements DynamicOjbect::try_parse. The try_parse method will attempt to parse the DynamicObject into a type implementing the Resource trait, using serde. Signed-off-by: Jessie Chatham Spencer <jessie@teainspace.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
Signed-off-by: Jessie Chatham Spencer jessie@teainspace.com
Motivation
Issue #1029 requests a method to convert a
DynamicObject
into aResource
. Such a method would avoid having to repeatedly implement this logic.Solution
This PR implements the
DynamicObject::try_parse
method to facilitate easy conversion from aDynamicObject
to aResource
. The method usesserde_json
to first serialize theDynamicObject
and then deserialize the JSON to theResource
.A small error type
ParseDynamicObjectError
has been implemented as well to represent a parsing failure. It wraps the originalserde_json::Error
so the original error information is preserved.