Skip to content

[Feature] user custom instantiators#243

Open
frecco75 wants to merge 1 commit intosta-szek:masterfrom
frecco75:feat/custom_instantiators
Open

[Feature] user custom instantiators#243
frecco75 wants to merge 1 commit intosta-szek:masterfrom
frecco75:feat/custom_instantiators

Conversation

@frecco75
Copy link
Copy Markdown
Collaborator

@frecco75 frecco75 commented Mar 24, 2020

The idea of this feature is to provide a mechanism for users to define custom instantiators like it exists for custom field value changers. It follows the same idea to let user extends pojo-tester mechanism.

It already exists a mechanism that let the user to select the choosen constructor (explanations here) but it is not efficient when the pojo use provided types from external libraries.

Here are the steps to add pojo tester support for an external librairy types (for example vavr) in an external project :

  1. Step 1 : define instantiator for custom types (vavr types for example). You have to inherits the UserObjectInstantiator class
  2. Step 2 : attach the custom instantiator :
    Instantiator.INSTANCE.attach(VavrTypesInstantiator.class);

Now we can use pojo tester with an object using vavr types, for example :

class User {
    private int id;
    private Option<String> email;  // Option is a Vavr type
}

Detailed example here with vavr collections.

@frecco75 frecco75 requested review from ekoutanov and sta-szek March 24, 2020 00:11
@frecco75 frecco75 changed the title [Feature] custom instantiators [Feature] user custom instantiators Mar 24, 2020
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

Successfully merging this pull request may close these issues.

1 participant