You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wondering if there is a solution for telling ffjson how to construct objects? Ideally ffjson would call a function that I define to return a new object. Then I could set default values etc., before unmarshalling (in the case that the field is not in the json)
In my case I have a large structure with many nested structures which ffjson ends up creating so it is not possible to set the defaults before unmarshalling.
e.g.,
type Foo struct {
A int
B int
}
type Bar struct {
A int
Foo *Foo
}
var bar Bar
ffjson.Unmarshal([]byte(`{ "a": 1, "foo": { "b": 2 } }`, &bar)
If the ffjson generated code called, for example, NewFoo() instead of new(Foo) I could set defaults (or perhaps do something else like Pooling if appropriate)
The text was updated successfully, but these errors were encountered:
I'm wondering if there is a solution for telling ffjson how to construct objects? Ideally ffjson would call a function that I define to return a new object. Then I could set default values etc., before unmarshalling (in the case that the field is not in the json)
In my case I have a large structure with many nested structures which ffjson ends up creating so it is not possible to set the defaults before unmarshalling.
e.g.,
If the ffjson generated code called, for example,
NewFoo()
instead ofnew(Foo)
I could set defaults (or perhaps do something else like Pooling if appropriate)The text was updated successfully, but these errors were encountered: