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

mechanism to construct objects? #236

Open
predmond opened this issue Oct 31, 2017 · 0 comments
Open

mechanism to construct objects? #236

predmond opened this issue Oct 31, 2017 · 0 comments

Comments

@predmond
Copy link

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)

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

1 participant