Skip to content

Constructors & generators composition #903

Answered by armandino
dcebotarenco asked this question in Q&A
Discussion options

You must be logged in to vote

@dcebotarenco - Instancio can populate objects via fields or setters. Unfortunately invoking constructors with arguments or static factories is not supported.

Currently, the closest is to use Keys.SET_BACK_REFERENCES, but this will bypass constructors with arguments, which is not what you're looking for.

Author author = Instancio.of(Author.class)
    .withSettings(Settings.create().set(Keys.SET_BACK_REFERENCES, true))
    .create();

I'll need to experiment a bit to see how feasible it is to implement something like this.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dcebotarenco
Comment options

Answer selected by dcebotarenco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants