Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Serializability of instance objects #1496

Open
nlm opened this issue Jan 11, 2023 · 0 comments
Open

Serializability of instance objects #1496

nlm opened this issue Jan 11, 2023 · 0 comments
Assignees
Labels
instance Instance issues, bugs and feature requests priority:medium Improvements that are not the main priority

Comments

@nlm
Copy link
Member

nlm commented Jan 11, 2023

I recently needed to serialize some objects from the go SDK and noticed that the objects do not serialize/deserialize consistently with the JSON encoding.

This is due to json:"-" tags in the go objects from the SDK.

Exemple:

type GetServerRequest struct {
    // Zone:
    //
    // Zone to target. If none is passed will use default zone from the config
    Zone scw.Zone `json:"-"`
    // ServerID: UUID of the server you want to get
    ServerID string `json:"-"`
}

I understand that this makes sense when generating request bodies because these fields are actually passed in the url. But, as a user of the SDK this behaviour is surprising and makes using these objects outside of just api requests difficult.

So i think you should either:

  • document this limitation
  • fix these objects so they can have a more standard behaviour

A possible workaround is having exported objects without the json tags and implementing internal objects that have the same structure but include the tags.

Example:

type GetServerRequest struct {
	Zone     string
	ServerID string
}

type internalGetServerRequest struct {
	Zone     string `json:"-"`
	ServerID string `json:"-"`
}

type GetServerResponse struct {
	// ...
}

func GetServer(ctx context.Context, req *GetServerRequest) (*GetServerResponse, error) {
	ireq := (*internalGetServerRequest)(req)
	// do the api call using json representation of ireq instead of req
}
@Codelax Codelax self-assigned this Jan 17, 2023
@remyleone remyleone added instance Instance issues, bugs and feature requests priority:high New features labels Jan 25, 2023
@remyleone remyleone added priority:medium Improvements that are not the main priority and removed priority:high New features labels Mar 10, 2023
@remyleone remyleone assigned remyleone and unassigned Codelax Mar 4, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
instance Instance issues, bugs and feature requests priority:medium Improvements that are not the main priority
Projects
None yet
Development

No branches or pull requests

3 participants