Skip to content
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

Translate to and from json #29

Open
dan-han-101 opened this issue Sep 11, 2023 · 0 comments
Open

Translate to and from json #29

dan-han-101 opened this issue Sep 11, 2023 · 0 comments

Comments

@dan-han-101
Copy link

Expected Behavior

Users often interact with objects in json format.

Would it make sense to update this SDK so that users can easily transform json strings into objects whose types match those defined in the CDEvent spec?

We currently have some code that looks like this

some_json_str = '...' # this could be consumed from kafka or some http service

typed_msg = CDEventMsgFactory.from_json(some_json_str) 
if isinstance(typed_msg, Taskrunstarted):
       # do something...
elif isinstance(typed_msg, Taskrunfinished):
       # do something...
etc...        

Along with verifying that the json is valid, we can also do some additional checks, like checking enum values, as specified in the schema.

We can then also go back to json with something like

new_json_str = CDEventMsgFactory.to_json(typed_msg) 

Actual Behavior

We wrote our own internal libraries, but we think it would be good to share this code, for others to re-use.

Steps to Reproduce the Problem

n/a

Specifications

  • Platform: Any
  • Python Version: Any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant