mergo icon indicating copy to clipboard operation
mergo copied to clipboard

feature: Allow Map() to handle when a struct has pointer fields as "optional"

Open leandrosansilva opened this issue 4 years ago • 1 comments
trafficstars

A common pattern is to use pointer fields as optional values, especially for structs which are serialized to json, for instance:

type myType struct {
  Value string `json:"value"`
  OptionalValue *int `json:"optionalValue,omitempty"`
}

Now we merge the following map to such type:

map[string]interface{} {
  "value": "some value",
  "optionalValue": 42,
}

And expect myType.OptionalValue to be allocated and set to 42.

leandrosansilva avatar Nov 05 '21 09:11 leandrosansilva

Hello, @leandrosansilva! This is your first Pull Request that will be reviewed by SourceLevel, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

sourcelevel-bot[bot] avatar Nov 05 '21 09:11 sourcelevel-bot[bot]

It won't be implemented, sorry.

darccio avatar Sep 11 '23 13:09 darccio