Class Keys
- Since:
- 1.1.10
- See Also:
-
Field Summary
FieldsModifier 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
<BeanValidationTarget> Specifies whether Bean Validation annotations are declared on fields or getters; default isBeanValidationTarget.FIELD
; property namebean.validation.target
.static final SettingKey
<Integer> Specifies thescale
for generatingBigDecimal
; default is2
; property namebigdecimal.scale
.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
<Boolean> Specifies whether internal exceptions should be propagated up; default isfalse
; property namefail.on.error
.static final SettingKey
<FeedDataAccess> Specifies whetherFeed
data is retrieved sequentially or randomly; default isFeedDataAccess.SEQUENTIAL
; property namefeed.data.access
.static final SettingKey
<FeedDataEndAction> Specifies the behaviour whenFeed
end of data has been reached (only applicable ifFEED_DATA_ACCESS
is set toFeedDataAccess.SEQUENTIAL
); default isFeedDataEndAction.FAIL
; property namefeed.data.end.action
.static final SettingKey
<FeedDataTrim> Specifies the trimming mode for feed data; default isFeedDataTrim.UNQUOTED
; property namefeed.data.trim
.static final SettingKey
<FeedFormatType> Specifies the feed format type; default isFeedFormatType.CSV
; property namefeed.format.type
.static final SettingKey
<String> static final SettingKey
<String> Specifies the default tag value for aFeed
; default isnull
(includes all tags); property namefeed.tag.value
.static final SettingKey
<FillType> Specifies the default value forFillType
which is used when populating objects via theInstancioObjectApi.fill()
method; default isFillType.POPULATE_NULLS_AND_DEFAULT_PRIMITIVES
; property namefill.type
.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 the number of samples for the@InstancioSource
annotation from theinstancio-junit
module; default is 100; property nameinstancio.source.samples
.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
<Boolean> Specifies whether values should be generated based on JPA annotations, such as@Column.length
; default isfalse
; property namejpa.enabled
.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
<Integer> The maximum number of attempts to generate an object for a given node; default is1000
; property namemax.generation.attempts
.static final SettingKey
<Mode> Specifies the mode: strict (unused selectors will trigger an exception) or lenient; default isMode.STRICT
; property namemode
.static final SettingKey
<OnFeedPropertyUnmatched> Specifies what should happen if a feed property is unmatched when using theapplyFeed()
method; default isOnFeedPropertyUnmatched.FAIL
; property nameon.feed.property.unmatched
.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
<OnSetMethodUnmatched> Specifies what should happen if a setter without a matching field is encountered; default isOnSetMethodUnmatched.IGNORE
; property nameon.set.method.unmatched
.static final SettingKey
<Boolean> Specifies whether initialised fields can be overwritten by the engine to random values; 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
<StringCase> Specifies the case of generated strings; default isStringCase.UPPER
; property namestring.case
.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
.static final SettingKey
<StringType> Specifies the String type to generate; default isStringType.ALPHABETIC
; property namestring.type
. -
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
- See Also:
-
BEAN_VALIDATION_TARGET
Specifies whether Bean Validation annotations are declared on fields or getters; default isBeanValidationTarget.FIELD
; property namebean.validation.target
.- Since:
- 3.4.0
- See Also:
-
BIG_DECIMAL_SCALE
Specifies thescale
for generatingBigDecimal
; default is2
; property namebigdecimal.scale
.- Since:
- 3.3.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
. -
FAIL_ON_ERROR
Specifies whether internal exceptions should be propagated up; default isfalse
; property namefail.on.error
.- Since:
- 3.0.1
-
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
. -
INSTANCIO_SOURCE_SAMPLES
Specifies the number of samples for the@InstancioSource
annotation from theinstancio-junit
module; default is 100; property nameinstancio.source.samples
.- Since:
- 5.0.0
-
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
. -
JPA_ENABLED
Specifies whether values should be generated based on JPA annotations, such as@Column.length
; default isfalse
; property namejpa.enabled
.- Since:
- 3.3.0
-
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
-
MAX_GENERATION_ATTEMPTS
The maximum number of attempts to generate an object for a given node; default is1000
; property namemax.generation.attempts
.This setting applicable to:
InstancioApi.filter(TargetSelector, FilterPredicate)
method- when generating values for hash-based collection
- Since:
- 5.0.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_FEED_PROPERTY_UNMATCHED
Specifies what should happen if a feed property is unmatched when using theapplyFeed()
method; default isOnFeedPropertyUnmatched.FAIL
; property nameon.feed.property.unmatched
.- Since:
- 5.2.0
- 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
.Warning:
OnSetMethodNotFound.FAIL
is not applied tofinal
fields since a field declared asfinal
cannot have a setter.- Since:
- 2.1.0
- See Also:
-
ON_SET_METHOD_UNMATCHED
Specifies what should happen if a setter without a matching field is encountered; default isOnSetMethodUnmatched.IGNORE
; property nameon.set.method.unmatched
.This setting is only applicable if
ASSIGNMENT_TYPE
is set toAssignmentType.METHOD
.The matching of fields and setter methods is based on the configured
SETTER_STYLE
setting.- Since:
- 4.0.0
- See Also:
-
OVERWRITE_EXISTING_VALUES
Specifies whether initialised fields can be overwritten by the engine to random values; default istrue
; property nameoverwrite.existing.values
.If this setting is set to
false
, then initialised values will not be overwritten by the engine, but they can still be overwritten via the API using a selector.Below are a few examples based on the following class:
class Foo { String value = "initial"; }
Example 1: initialised value is overwritten with a random value because by default
OVERWRITE_EXISTING_VALUES
istrue
.// Sample output: Foo[value=VEQHJ] Foo foo = Instancio.create(Foo.class);
Example 2: initialised value is preserved when
OVERWRITE_EXISTING_VALUES
isfalse
.// Output: Foo[value=initial] Foo foo = Instancio.of(Foo.class) .set(Keys.OVERWRITE_EXISTING_VALUES, false) .create();
Example 3: initialised value can be overwritten using a selector regardless of the
OVERWRITE_EXISTING_VALUES
setting.// Output: Foo[value=Hello] Foo foo = Instancio.of(Foo.class) .set(Keys.OVERWRITE_EXISTING_VALUES, false) .set(field(Foo::getValue), "Hello") .create();
- Since:
- 2.0.0
-
FEED_DATA_ACCESS
Specifies whetherFeed
data is retrieved sequentially or randomly; default isFeedDataAccess.SEQUENTIAL
; property namefeed.data.access
.- Since:
- 5.0.0
- See Also:
-
FEED_DATA_END_ACTION
Specifies the behaviour whenFeed
end of data has been reached (only applicable ifFEED_DATA_ACCESS
is set toFeedDataAccess.SEQUENTIAL
); default isFeedDataEndAction.FAIL
; property namefeed.data.end.action
.- Since:
- 5.0.0
- See Also:
-
FEED_DATA_TRIM
Specifies the trimming mode for feed data; default isFeedDataTrim.UNQUOTED
; property namefeed.data.trim
.- Since:
- 5.0.0
- See Also:
-
FEED_FORMAT_TYPE
Specifies the feed format type; default isFeedFormatType.CSV
; property namefeed.format.type
.- Since:
- 5.0.0
- See Also:
-
FEED_TAG_KEY
- Since:
- 5.0.0
- See Also:
-
FEED_TAG_VALUE
Specifies the default tag value for aFeed
; default isnull
(includes all tags); property namefeed.tag.value
.- Since:
- 5.0.0
- See Also:
-
FILL_TYPE
Specifies the default value forFillType
which is used when populating objects via theInstancioObjectApi.fill()
method; default isFillType.POPULATE_NULLS_AND_DEFAULT_PRIMITIVES
; property namefill.type
.- Since:
- 5.3.0
- See Also:
-
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
. -
STRING_CASE
Specifies the case of generated strings; default isStringCase.UPPER
; property namestring.case
.- Since:
- 4.8.0
-
STRING_TYPE
Specifies the String type to generate; default isStringType.ALPHABETIC
; property namestring.type
.- Since:
- 4.7.0
-
-
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
-