class whenAbsent[+T] extends Annotation with StaticAnnotation
An alternative way to provide default value for case class parameter used during deserialization with GenCodec
when its field is missing in data being deserialized. Normally, Scala-level default parameter values are picked
up, but you may want to use this annotation instead if you don't want to pollute your Scala classes with
unintended default parameter values (i.e. you want a default value *only* for deserialization).
case class HasDefault(@whenAbsent("default") str: String) object HasDefault extends HasGenCodec[HasDefault]
If a parameter has both Scala-level default value and is annotated with @whenAbsent
then value from annotation
takes priority. You can use this to have different source-level default value and different
default value for deserialization. You can also leverage this to "remove" default value for deserialization:
case class HasNoDefault(@whenAbsent(throw new Exception) str: String = "default") object HasDefault extends HasGenCodec[HasDefault]
NOTE: whenAbsent also works for method parameters in RPC framework.
- Alphabetic
- By Inheritance
- whenAbsent
- StaticAnnotation
- Annotation
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new whenAbsent(v: ⇒ T)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
- def value: T
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )