public class IfDefault extends ValueIf<Object> implements InitializeIf
This condition tests against the default value of the field that it is placed upon, whatever that default may be. If you initialize the field with a value, this condition will use that value as the comparison. For example, if you have a class like this:
public class MyEntity { @Id Long id; @IgnoreSave(IfDefault.class) String foo = "defaultFoo"; }
The foo
field will be left unsaved when it has the value "defaultFoo".
Specifically, this conditional constructs an instance of the class in which the field is declared and stores the default field value for later comparison. Note that if you initialize the field in your default constructor, this counts!
There is one important caveat: Objectify treats each declared class in a type hierarchy separately. The class in which the field is declared have a no-arg constructor, and it alone is used to determine the default value. This will NOT work:
public class MyBase { @Id Long id; @IgnoreSave(IfDefault.class) String foo = "baseFoo"; } public class MyEntity extends MyBase { public MyEntity() { foo = "subclassFoo"; } }
In this example, the default value will be "baseFoo".
Constructor and Description |
---|
IfDefault() |
Modifier and Type | Method and Description |
---|---|
void |
init(ObjectifyFactory fact,
Field field)
Instructs the condition instance which field it lives on.
|
boolean |
matchesValue(Object value)
Test a simple property value.
|
matchesPojo
public void init(ObjectifyFactory fact, Field field)
InitializeIf
init
in interface InitializeIf
fact
- is just handy to have aroundfield
- is the field which has the annotation with this condition.public boolean matchesValue(Object value)
If
matchesValue
in interface If<Object,Object>
value
- is the actual value of a particular fieldCopyright © 2016. All rights reserved.