Annotation Type B2Json.optionalWithDefault


  • @Retention(RUNTIME)
    @Target(FIELD)
    public static @interface B2Json.optionalWithDefault
    Field annotation that says a field is optional. When deserializing, the provided default value will be used. The default provided should be the JSON form of the value, as a string. The value will almost always be included when serializing, with two exceptions. If omitNull is true and the value is null, it will be left out of the serialized representation. Similarly, if omitZero is true and the value is zero, it will be left out of the serialized representation. Note that both omitNull and omitZero default to false. A B2JsonException is thrown when omitNull is set to true on a primitive field; primitives are not nullable objects so omitNull does not apply. Similarly, a B2JsonException is thrown when omitZero is set to true on a field that's either non-numeric, non-primitive, or not built into B2Json. Note that they can't both be used on the same field because one only works on non-primitive fields and the other only works on primitive fields.
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String defaultValue  
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean omitNull  
      boolean omitZero  
    • Element Detail

      • defaultValue

        java.lang.String defaultValue
      • omitNull

        boolean omitNull
        Default:
        false
      • omitZero

        boolean omitZero
        Default:
        false