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

Do not use json.RawMessage for untyped request arguments #90

Open
dottedmag opened this issue Feb 7, 2024 · 2 comments
Open

Do not use json.RawMessage for untyped request arguments #90

dottedmag opened this issue Feb 7, 2024 · 2 comments

Comments

@dottedmag
Copy link

Using json.RawMessage for request arguments makes the users of go-dap unnecessary cumbersome. any would be a better choice. Compare

msg, err := json.Marshal(someArgs)
if err != nil {
    ....
}
AttachRequest {
	Arguments: json.RawMessage(msg),
}

and

AttachRequest {
        Arguments: someArgs,
}
@corneliusweig
Copy link
Collaborator

I don't quite agree. In fact I suggested to treat more submessages as RawMessage (#88).

With any or map[string]any submessages I need to do a lot of type casting when accessing fields in that message. This is cumbersome and error-prone. Instead, when there is a RawMessage, I can Unmarshal the message into a user-defined type of my choice. Then accessing fields in this submessage is type-safe and easy.

So I think that RawMessage is much more type safe and easier to handle.

@dottedmag
Copy link
Author

This is for request arguments.

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

2 participants