Skip to content

Translate to and from json #29

@dan-han-101

Description

@dan-han-101

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions