Does any one have any tips for Unmarshaling respon...
# ask-the-community
g
Does any one have any tips for Unmarshaling responses from flyte admin (in Go)? For example when I send a GET to
/api/v1/data/executions/{id}
with a execution id, the json response I get can't be Unmarshaled to the proper struct (located here). I'm especially having a hard time Unmarshaling `core.Literal`s
s
cc: @Yee @Kevin Su
e
@George D. Torres, can you share some of the code you're using? Also, can you paste a stacktrace of the error you're seeing?
g
@Eduardo Apolinario (eapolinario) thank you! I'm afk today, but I'll put that here tomorrow
@Eduardo Apolinario (eapolinario) I am taking my GET response from
/api/v1/data/executions/{id}
(the raw json for that response is attached). Then I Unmarshal that into an
admin.WorkflowExecutionGetDataResponse
(which appears to be the correct output model according to the swagger docs) using the following code:
Copy code
data := admin.WorkflowExecutionGetDataResponse{}
err := json.Unmarshal(data_json, &data) // data_json is the raw response from flyte      

if err != nil {
        c.Data(status, "application/json", data_json) // return raw json
        return
}
c.JSON(status, data) // return unmarshalled object as json
It does successfully Unmarshal, but the resulting unmarshaled object
null
in all of the places the literals should be (see unmarshalled json attachment).
k
hey @George D. Torres for json unmarshalling you'll want to use jsonpb, like we do here: https://github.com/flyteorg/flytestdlib/blob/4c2902e01eb526e9bac3bbfa29013c673ba6a7a8/utils/marshal_utils.go#L31
(it's frustrating because the json unmarshalling will happily not return an err even when it fails to populate the message 😞)
g
Appreciated! I'll give that a shot
110 Views