@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface SerdeSkipDeserializingIf
class MyObject {
@SerdeSkipSerializingIf(SkipDeIf.IS_MISSING)
String name;
}
class MyObject {
@SerdeSkipSerializingIf(SkipDeIf.IS_EMPTY)
List<String> servers;
}
class MyObject {
// The field will not be modified if the config value is missing or null.
@SerdeSkipSerializingIf({SkipDeIf.IS_MISSING, SkipDeIf.IS_NULL})
String name;
}
class MyObject {
@SerdeSkipSerializingIf(value = SkipDeIf.CUSTOM, customCheck="skipName")
String name;
private boolean skipName(Object nameInConfig) {
return nameInConfig == null ||
nameInConfig == NullObject.NULL_OBJECT ||
nameInConfig.equals("skip me");
}
}
class MyObject {
@SerdeSkipSerializingIf(value = {SkipDeIf.CUSTOM}, customClass=SkipChecker.class, customCheck="skipName")
String name;
@SerdeSkipSerializingIf(value = {SkipDeIf.CUSTOM}, customClass=SkipChecker.class, customCheck="skipId")
int id;
}
class SkipChecker {
// The predicate can be defined by a `Predicate` field too!
static final Predicate<Object> skipName = nameInConfig -> nameInConfig == null ||
nameInConfig == NullObject.NULL_OBJECT ||
nameInConfig.equals("skip me");
// Note that skip predicates defined in another class must be static.
static boolean skipId(Object idInConfig) {
return idInConfig instanceof Integer && ((int)idInConfig) == -1;
}
}
| Modifier and Type | Required Element and Description |
|---|---|
SerdeSkipDeserializingIf.SkipDeIf[] |
value
The type of skip predicate: either a predefined condition, or
CUSTOM. |
| 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 deserializing should
be skipped.
|
java.lang.Class<?> |
customClass
The class where to find the custom skip predicate.
|
public abstract SerdeSkipDeserializingIf.SkipDeIf[] value
CUSTOM.
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
UnmodifiableConfig.getRaw(java.util.List).
Object.
If customClass() is set to its non-default value, the method must be static.
java.util.function.Predicate<Object>.
In most cases, the predicate field should be declared with the
transient keyword, to prevent it from being (de)serialized.Predicate