@Repeatable(value=SerdeAssertsContainer.class) @Retention(value=RUNTIME) @Target(value=FIELD) public @interface SerdeAssert
import com.electronwill.nightconfig.core.serde.annotations.SerdeAssert;
import com.electronwill.nightconfig.core.serde.annotations.SerdeAssert.AssertThat;
class MyObject {
@SerdeAssert(AssertThat.NOT_NULL)
String nonNull;
}
@SerdeAssert are always applied on the
value of the java field. If the field's value is replaced by a default
value, the assertions are applied on the default value.
| Modifier and Type | Required Element and Description |
|---|---|
SerdeAssert.AssertThat[] |
value
One or multiple assertions to check.
|
| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
customCheck
The name of the field or method that defines the predicate to apply
in order to test whether the field that we are (de)serializing
satisfies a condition.
|
java.lang.Class<?> |
customClass
The class where to find the custom assertion predicate.
|
SerdePhase |
phase
Controls whether the assert value applies when Serializing and/or
Deserializing.
|
public abstract SerdeAssert.AssertThat[] value
If multiple assertions are specified, they are combined with a logical AND, that is, they must all be true for the assertion to succeed.
If set to CUSTOM, you must provide the customCheck()
parameter,
and you may provide the customClass() parameter.
public abstract java.lang.Class<?> customClass
By default, it is set to Object.class, which is treated as a special
value.
It means that the actual class to use is the one of the object that is
currently being (de)serialized.
customCheck()public abstract java.lang.String customCheck
T, where
T is the type of the field to (de)serialize.
If customClass() is set to its non-default value, the method must be
static.
java.util.function.Predicate<T>,
where T is the type of the field to (de)serialize.
In most cases, the predicate field should be declared with the
transient keyword, to prevent it from being (de)serialized.Predicatepublic abstract SerdePhase phase