@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface SerdeSkipSerializingIf
class MyObject {
@SerdeSkipSerializingIf(SkipSerIf.IS_NULL)
String name;
}
class MyObject {
@SerdeSkipSerializingIf(SkipSerIf.IS_EMPTY)
List<String> servers;
}
class MyObject {
@SerdeSkipSerializingIf(value = SkipSerIf.CUSTOM, customCheck="skipName")
String name;
private boolean skipName(String name) {
return name == null || name.equals("skip me");
}
}
class MyObject {
@SerdeSkipSerializingIf(value = SkipSerIf.CUSTOM, customClass=SkipChecker.class, customCheck="skipName")
String name;
@SerdeSkipSerializingIf(value = SkipSerIf.CUSTOM, customClass=SkipChecker.class, customCheck="skipId")
int id;
}
class SkipChecker {
// The predicate can be defined by a `Predicate` field too!
static final Predicate<String> skipName = name -> name == null || name.equals("skip me");
// Note that skip predicates defined in another class must be static.
static boolean skipId(int id) {
return id == -1; // skip if id is -1
}
}
| Modifier and Type | Required Element and Description |
|---|---|
SerdeSkipSerializingIf.SkipSerIf[] |
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 serializing should
be skipped.
|
java.lang.Class<?> |
customClass
The class where to find the custom skip predicate.
|
public abstract SerdeSkipSerializingIf.SkipSerIf[] 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
T, where
T is the type of the field to 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 serialize.
In most cases, the predicate field should be declared with the
transient keyword, to prevent it from being (de)serialized.Predicate