Skip to content

mechanism to construct objects? #236

Description

@predmond

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions