public class FieldSupport extends Object
Modifier and Type | Method and Description |
---|---|
<T> T |
fieldValue(String fieldName,
Class<T> clazz,
Object target)
Return the value of field from a target object.
|
<T> List<T> |
fieldValues(String fieldName,
Class<T> fieldClass,
Iterable<?> target)
|
<T> List<T> |
fieldValues(String fieldName,
Class<T> fieldClass,
Object[] target)
|
List<Object> |
fieldValues(String fieldName,
Iterable<?> target) |
static FieldSupport |
instance()
Returns the singleton instance of this class.
|
static void |
setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields)
Globally set whether
and
should be allowed to extract private fields, if not and they try it fails with exception. |
public static FieldSupport instance()
public static void setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields)
IterableAssert#extracting(String)
and
ObjectArrayAssert#extracting(String)
should be allowed to extract private fields, if not and they try it fails with exception.allowExtractingPrivateFields
- allow private fields extraction. Default true
.public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Iterable<?> target)
List
containing the values of the given field name, from the elements of the given
Iterable
. If the given Iterable
is empty or null
, this method will return an
empty List
. This method supports nested fields (e.g. "address.street.number").fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.fieldClass
- the expected type of the given field.target
- the given Iterable
.Iterable
containing the values of the given field name, from the elements of the given
Iterable
.IntrospectionError
- if an element in the given Iterable
does not have a field with a matching name.public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Object[] target)
List
containing the values of the given field name, from the elements of the given
Iterable
. If the given Iterable
is empty or null
, this method will return an
empty List
. This method supports nested fields (e.g. "address.street.number").fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.fieldClass
- the expected type of the given field.target
- the given Iterable
.Iterable
containing the values of the given field name, from the elements of the given
Iterable
.IntrospectionError
- if an element in the given Iterable
does not have a field with a matching name.public <T> T fieldValue(String fieldName, Class<T> clazz, Object target)
fieldName
- the name of the field. It may be a nested field. It is left to the clients to validate for
null
or empty.target
- the given objectclazz
- type of fieldIntrospectionError
- if the given target does not have a field with a matching name.Copyright © 2013-2014 AssertJ. All Rights Reserved.