Class Keys
- Since:
- 1.1.10
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final SettingKey<AfterGenerate>
Specifies the default value of theAfterGenerate
hint supplied from custom generators to the engine; default isAfterGenerate.POPULATE_NULLS_AND_DEFAULT_PRIMITIVES
; property namehint.after.generate
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for array elements; default isfalse
; property namearray.elements.nullable
.static final SettingKey<Integer>
Specifies maximum length for arrays; default is 6; property namearray.max.length
.static final SettingKey<Integer>
Specifies minimum length for arrays; default is 2; property namearray.min.length
.static final SettingKey<Boolean>
Specifies whether a null can be generated for arrays; default isfalse
; property namearray.nullable
.static final SettingKey<AssignmentType>
Specifies whether to assign values using fields or methods; default isAssignmentType.FIELD
; property nameassignment.type
.static final SettingKey<Boolean>
Specifies whether values should be generated based on Jakarta Bean Validation 3.0 annotations, if present; default isfalse
; property namebean.validation.api.enabled
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Boolean type; default isfalse
; property nameboolean.nullable
.static final SettingKey<Byte>
Specifies maximum value for bytes; default is 127; property namebyte.max
.static final SettingKey<Byte>
Specifies minimum value for bytes; default is 1; property namebyte.min
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Byte type; default isfalse
; property namebyte.nullable
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Character type; default isfalse
; property namecharacter.nullable
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for collection elements; default isfalse
; property namecollection.elements.nullable
.static final SettingKey<Integer>
Specifies maximum size for collections; default is 6; property namecollection.max.size
.static final SettingKey<Integer>
Specifies minimum size for collections; default is 2; property namecollection.min.size
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for collections; default isfalse
; property namecollection.nullable
.static final SettingKey<Double>
Specifies maximum value for doubles; default is 10000; property namedouble.max
.static final SettingKey<Double>
Specifies minimum value for doubles; default is 1; property namedouble.min
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Double type; default isfalse
; property namedouble.nullable
.static final SettingKey<Float>
Specifies maximum value for floats; default is 10000; property namefloat.max
.static final SettingKey<Float>
Specifies minimum value for floats; default is 1; property namefloat.min
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Float type; default isfalse
; property namefloat.nullable
.static final SettingKey<Integer>
Specifies maximum value for integers; default is 10000; property nameinteger.max
.static final SettingKey<Integer>
Specifies minimum value for integers; default is 1; property nameinteger.min
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Integer type; default isfalse
; property nameinteger.nullable
.static final SettingKey<Long>
Specifies maximum value for longs; default is 10000; property namelong.max
.static final SettingKey<Long>
Specifies minimum value for longs; default is 1; property namelong.min
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Long type; default isfalse
; property namelong.nullable
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for map keys; default isfalse
; property namemap.keys.nullable
.static final SettingKey<Integer>
Specifies maximum size for maps; default is 6; property namemap.max.size
.static final SettingKey<Integer>
Specifies minimum size for maps; default is 2; property namemap.min.size
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for maps; default isfalse
; property namemap.nullable
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for map values; default isfalse
; property namemap.values.nullable
.static final SettingKey<Integer>
Specifies the maximum depth of the generated object tree; default is8
; property namemax.depth
.static final SettingKey<Mode>
Specifies the mode: strict (unused selectors will trigger an exception) or lenient; default isMode.STRICT
; property namemode
.static final SettingKey<OnSetFieldError>
Specifies what should happen if an error occurs setting a field's value; default isOnSetFieldError.IGNORE
; property nameon.set.field.error
.static final SettingKey<OnSetMethodError>
Specifies what should happen if an error occurs invoking a setter; default isOnSetMethodError.ASSIGN_FIELD
; property nameon.set.method.error
.static final SettingKey<OnSetMethodNotFound>
Specifies what should happen if a setter method for a field cannot be resolved; default isOnSetMethodNotFound.ASSIGN_FIELD
; property nameon.set.method.not.found
.static final SettingKey<Boolean>
Specifies whether initialised fields are allowed to be overwritten; default istrue
; property nameoverwrite.existing.values
.static final SettingKey<Long>
Specifies the seed value; default isnull
; property nameseed
.static final SettingKey<Boolean>
Specifies whether back references should be set for cyclic classes; default isfalse
(cycles are terminated withnull
); property nameset.back.references
.static final SettingKey<Integer>
Specifies modifier exclusions for setter-methods; default is0
(no exclusions); property namesetter.exclude.modifier
.static final SettingKey<SetterStyle>
Indicates the naming convention of setter methods to use; default isSetterStyle.SET
; property namesetter.style
.static final SettingKey<Short>
Specifies maximum value for shorts; default is 10000; property nameshort.max
.static final SettingKey<Short>
Specifies minimum value for shorts; default is 1; property nameshort.min
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for Short type; default isfalse
; property nameshort.nullable
.static final SettingKey<Boolean>
Specifies whether an empty string can be generated; default isfalse
; property namestring.allow.empty
.static final SettingKey<Boolean>
Specifies whether generated Strings should be prefixed with field names; default isfalse
; property namestring.field.prefix.enabled
.static final SettingKey<Integer>
Specifies maximum length of strings; default is 10; property namestring.max.length
.static final SettingKey<Integer>
Specifies minimum length of strings; default is 3; property namestring.min.length
.static final SettingKey<Boolean>
Specifies whether anull
can be generated for String type; default isfalse
; property namestring.nullable
. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<SettingKey<Object>>
all()
Returns all keys supported by Instancio.static <T> SettingKey<T>
Returns aSettingKey
instance with the given property key.static <T> SettingKey.SettingKeyBuilder<T>
A builder for creating custom setting keys.
-
Field Details
-
ASSIGNMENT_TYPE
Specifies whether to assign values using fields or methods; default isAssignmentType.FIELD
; property nameassignment.type
.This setting does not apply to fields that are
final
andrecord
classes, since those cannot have setters.- Since:
- 2.1.0
- See Also:
-
AFTER_GENERATE_HINT
Specifies the default value of theAfterGenerate
hint supplied from custom generators to the engine; default isAfterGenerate.POPULATE_NULLS_AND_DEFAULT_PRIMITIVES
; property namehint.after.generate
.- Since:
- 2.0.0
- See Also:
-
ARRAY_ELEMENTS_NULLABLE
Specifies whether anull
can be generated for array elements; default isfalse
; property namearray.elements.nullable
. -
ARRAY_MIN_LENGTH
Specifies minimum length for arrays; default is 2; property namearray.min.length
. -
ARRAY_MAX_LENGTH
Specifies maximum length for arrays; default is 6; property namearray.max.length
. -
ARRAY_NULLABLE
Specifies whether a null can be generated for arrays; default isfalse
; property namearray.nullable
. -
BEAN_VALIDATION_ENABLED
Specifies whether values should be generated based on Jakarta Bean Validation 3.0 annotations, if present; default isfalse
; property namebean.validation.api.enabled
.- Since:
- 2.7.0
-
BOOLEAN_NULLABLE
Specifies whether anull
can be generated for Boolean type; default isfalse
; property nameboolean.nullable
. -
BYTE_MIN
Specifies minimum value for bytes; default is 1; property namebyte.min
. -
BYTE_MAX
Specifies maximum value for bytes; default is 127; property namebyte.max
. -
BYTE_NULLABLE
Specifies whether anull
can be generated for Byte type; default isfalse
; property namebyte.nullable
. -
CHARACTER_NULLABLE
Specifies whether anull
can be generated for Character type; default isfalse
; property namecharacter.nullable
. -
COLLECTION_ELEMENTS_NULLABLE
Specifies whether anull
can be generated for collection elements; default isfalse
; property namecollection.elements.nullable
. -
COLLECTION_MIN_SIZE
Specifies minimum size for collections; default is 2; property namecollection.min.size
. -
COLLECTION_MAX_SIZE
Specifies maximum size for collections; default is 6; property namecollection.max.size
. -
COLLECTION_NULLABLE
Specifies whether anull
can be generated for collections; default isfalse
; property namecollection.nullable
. -
DOUBLE_MIN
Specifies minimum value for doubles; default is 1; property namedouble.min
. -
DOUBLE_MAX
Specifies maximum value for doubles; default is 10000; property namedouble.max
. -
DOUBLE_NULLABLE
Specifies whether anull
can be generated for Double type; default isfalse
; property namedouble.nullable
. -
FLOAT_MIN
Specifies minimum value for floats; default is 1; property namefloat.min
. -
FLOAT_MAX
Specifies maximum value for floats; default is 10000; property namefloat.max
. -
FLOAT_NULLABLE
Specifies whether anull
can be generated for Float type; default isfalse
; property namefloat.nullable
. -
INTEGER_MIN
Specifies minimum value for integers; default is 1; property nameinteger.min
. -
INTEGER_MAX
Specifies maximum value for integers; default is 10000; property nameinteger.max
. -
INTEGER_NULLABLE
Specifies whether anull
can be generated for Integer type; default isfalse
; property nameinteger.nullable
. -
LONG_MIN
Specifies minimum value for longs; default is 1; property namelong.min
. -
LONG_MAX
Specifies maximum value for longs; default is 10000; property namelong.max
. -
LONG_NULLABLE
Specifies whether anull
can be generated for Long type; default isfalse
; property namelong.nullable
. -
MAP_KEYS_NULLABLE
Specifies whether anull
can be generated for map keys; default isfalse
; property namemap.keys.nullable
. -
MAP_MIN_SIZE
Specifies minimum size for maps; default is 2; property namemap.min.size
. -
MAP_MAX_SIZE
Specifies maximum size for maps; default is 6; property namemap.max.size
. -
MAP_NULLABLE
Specifies whether anull
can be generated for maps; default isfalse
; property namemap.nullable
. -
MAP_VALUES_NULLABLE
Specifies whether anull
can be generated for map values; default isfalse
; property namemap.values.nullable
. -
MAX_DEPTH
Specifies the maximum depth of the generated object tree; default is8
; property namemax.depth
.- Since:
- 2.7.0
-
MODE
Specifies the mode: strict (unused selectors will trigger an exception) or lenient; default isMode.STRICT
; property namemode
.- Since:
- 1.3.3
- See Also:
-
ON_SET_FIELD_ERROR
Specifies what should happen if an error occurs setting a field's value; default isOnSetFieldError.IGNORE
; property nameon.set.field.error
.Warning: an error caused by assigning an incompatible type is considered a user error and is never ignored, despite this setting.
- Since:
- 2.1.0
- See Also:
-
ON_SET_METHOD_ERROR
Specifies what should happen if an error occurs invoking a setter; default isOnSetMethodError.ASSIGN_FIELD
; property nameon.set.method.error
.- Since:
- 2.1.0
- See Also:
-
ON_SET_METHOD_NOT_FOUND
Specifies what should happen if a setter method for a field cannot be resolved; default isOnSetMethodNotFound.ASSIGN_FIELD
; property nameon.set.method.not.found
.- Since:
- 2.1.0
- See Also:
-
OVERWRITE_EXISTING_VALUES
Specifies whether initialised fields are allowed to be overwritten; default istrue
; property nameoverwrite.existing.values
.- Since:
- 2.0.0
-
SEED
Specifies the seed value; default isnull
; property nameseed
.- Since:
- 1.5.1
-
SET_BACK_REFERENCES
Specifies whether back references should be set for cyclic classes; default isfalse
(cycles are terminated withnull
); property nameset.back.references
.For example, given the following classes:
class Order { List<OrderItem> items; } class OrderItem { Order order; }
If
SET_BACK_REFERENCES
is disabled, creating an instance ofOrder
would result in theOrderItem.order
field beingnull
:Order order = Instancio.create(Order.class); assertThat(order.getItems()).allSatisfy(item -> assertThat(item.getOrder()).isNull() );
If
SET_BACK_REFERENCES
is enabled, creating an instance ofOrder
would result in theOrderItem.order
field being set to the parent order:Settings settings = Settings.create().set(Keys.SET_BACK_REFERENCES, true); Order order = Instancio.of(Order.class) .withSettings(settings) .create(); assertThat(order.getItems()).allSatisfy(item -> assertThat(item.getOrder()).isSameAs(order) );
- Since:
- 3.0.0
-
SETTER_EXCLUDE_MODIFIER
Specifies modifier exclusions for setter-methods; default is0
(no exclusions); property namesetter.exclude.modifier
.This setting can be used to control which setter methods are allowed to be invoked (based on method modifiers) when
ASSIGNMENT_TYPE
is set toAssignmentType.METHOD
). For instance, using this setting, it is possible to restrict method assignment topublic
setters only (by default, a setter is invoked even if it isprivate
).Multiple modifiers can be specified using logical
OR
operator. For example, the following allows onlypublic
methods:int exclusions = MethodModifier.PACKAGE_PRIVATE | MethodModifier.PROTECTED | MethodModifier.PRIVATE; Settings.create().set(Keys.SETTER_EXCLUDE_MODIFIER, exclusions);
- Since:
- 2.16.0
- See Also:
-
SETTER_STYLE
Indicates the naming convention of setter methods to use; default isSetterStyle.SET
; property namesetter.style
.- Since:
- 2.1.0
- See Also:
-
SHORT_MIN
Specifies minimum value for shorts; default is 1; property nameshort.min
. -
SHORT_MAX
Specifies maximum value for shorts; default is 10000; property nameshort.max
. -
SHORT_NULLABLE
Specifies whether anull
can be generated for Short type; default isfalse
; property nameshort.nullable
. -
STRING_ALLOW_EMPTY
Specifies whether an empty string can be generated; default isfalse
; property namestring.allow.empty
. -
STRING_FIELD_PREFIX_ENABLED
Specifies whether generated Strings should be prefixed with field names; default isfalse
; property namestring.field.prefix.enabled
.- Since:
- 2.4.0
-
STRING_MIN_LENGTH
Specifies minimum length of strings; default is 3; property namestring.min.length
. -
STRING_MAX_LENGTH
Specifies maximum length of strings; default is 10; property namestring.max.length
. -
STRING_NULLABLE
Specifies whether anull
can be generated for String type; default isfalse
; property namestring.nullable
.
-
-
Method Details
-
all
Returns all keys supported by Instancio.- Returns:
- all keys
-
get
Returns aSettingKey
instance with the given property key.- Parameters:
key
- to lookup- Returns:
- the setting key, or
null
if none found
-
ofType
A builder for creating custom setting keys.When defining custom keys, specifying
SettingKey.SettingKeyBuilder.withPropertyKey(String)
is optional since not all settings will be defined in a properties file. IfwithPropertyKey()
is not specified, then a random property key will be assigned.- Type Parameters:
T
- the value type- Parameters:
type
- of the value the key is associated with, notnull
- Returns:
- key builder
- Since:
- 2.12.0
-