We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I very like this repo, but it's confused me.
This's a use safetypes's struct
type Dog struct { Name Option[string] `json:"name,omitempty"` }
json.Unmarshal input json:
{"name":"hello"}
it get: Dog{Name:nil}
Dog{Name:nil}
If in the rust, input json:
rust get like: Dog{Name:Option("hello")}
Dog{Name:Option("hello")}
Ok, I now Option is struct { Value: *T }, bug frontend developer don't like {"name":{"value":"hello"}}.
struct { Value: *T }
{"name":{"value":"hello"}}
I can use flat fn, flat server response, delete *value:
func flatOptionValue(target any) { if data, ok := target.(map[string]any); ok { for key, item := range data { if m, ok := item.(map[string]any); ok { if v, ok := m["value"]; ok && len(m) == 1 { data[key] = v flatOptionValue(v) continue } flatOptionValue(m) } } } else if arr, ok := target.([]any); ok { for _, v := range arr { flatOptionValue(v) } } }
But I can't json.Unmarshal the {"name":"hello"} json to struct.
The text was updated successfully, but these errors were encountered:
okay i'll look into it
Sorry, something went wrong.
@ymzuiku latest commit should fix the problem could you test it?
No branches or pull requests
I very like this repo, but it's confused me.
This's a use safetypes's struct
json.Unmarshal input json:
it get:
Dog{Name:nil}
If in the rust, input json:
rust get like:
Dog{Name:Option("hello")}
Ok, I now Option is
struct { Value: *T }
, bug frontend developer don't like{"name":{"value":"hello"}}
.I can use flat fn, flat server response, delete *value:
But I can't json.Unmarshal the
{"name":"hello"}
json to struct.The text was updated successfully, but these errors were encountered: