Modification
OBJECTO
Objecto provides a powerful mechanism to customize and adapt generated objects based on specific requirements or scenarios. This flexibility enables developers to tailor objects to their exact needs, ensuring that the generated data aligns with the desired context. Objecto supports the modification of generated objects through both parameters of factory methods and modifier methods.
@Modifier
Parameters
Specify modification parameters using @Modifier
annotation in factory methods to alter specific fields or invoke methods during generation.
When the code is compiled with the -parameters
flag, the parameter names are retained in the compiled bytecode. This means that Objecto can infer the parameters without the explicit use of @Modifier
. Developers can choose whether to use @Modifier
for clarity or rely on parameter names when compiling with the -parameters
flag.
Example:
Methods
Define @Modifier
methods with a return type of the factory interface itself.
Example:
Complex Modifiers
Modifiers can also be complex, allowing modification of nested fields or collections.
Examples:
Applying Modifications to Custom Factory Methods
Developers can apply modifications to custom factory methods using the modifier methods provided by the factory interface.
Example:
Last updated