Annotation Interface JSonAttribute


@Documented @Retention(RUNTIME) @Target(FIELD) public @interface JSonAttribute
The JBStrap framework allows any JAVA class to be converted into a JSON object. This annotation is can be assigned to a class' fields, and during the conversion, the field value's can be set to be converted. If a class is converted into a JSON object, only the fields that had this annotation will be in the object.
Since:
4.0
Author:
JBStrap
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Use this option to specify if the field contains a Java object, which field in the JSON object should be the value from the Java class instead of the value of the field.
    Use this option to specify if the field contains a Java object, which field in the JSON object should be replaced with the Java class method's return value should be used for the value of the field.
    Sets the name of the attribute that is in the JSON object If not specified, the attribute name will be the same as the field name
    The format used when converting Date values into String.
    boolean
    Converts the empty value (ie, empty string or list) to a null value.If it's set to true, the empty values will appear as null in the JSON object.
    Sets the name of the data formatter method.
  • Element Details

    • attributeName

      String attributeName
      Sets the name of the attribute that is in the JSON object If not specified, the attribute name will be the same as the field name
      Returns:
      The name of the attribute that is in the JSON object
      Default:
      ""
    • emptyValueAsNull

      boolean emptyValueAsNull
      Converts the empty value (ie, empty string or list) to a null value.If it's set to true, the empty values will appear as null in the JSON object. If set to false, it will be an empty value. If not set, empty values will be null
      Returns:
      true, if the empty values will be converted into null
      Default:
      true
    • dateFormat

      String dateFormat
      The format used when converting Date values into String. If not specified, the default format will be used, which is "yyyy-MM-dd'T'HH:mm:ss"
      Returns:
      The format used when generating JSON
      Default:
      "yyyy-MM-dd\'T\'HH:mm:ss"
    • alternativeField

      String alternativeField

      Use this option to specify if the field contains a Java object, which field in the JSON object should be the value from the Java class instead of the value of the field. It is recommended to use this, if you want to place different values in the JSON object, based on an ENUM.

      Returns:
      The name of the field, that has the value, that will be in the JSON object.
      Default:
      ""
    • alternativeMethod

      String alternativeMethod

      Use this option to specify if the field contains a Java object, which field in the JSON object should be replaced with the Java class method's return value should be used for the value of the field.

      Returns:
      The name of the field, which has the value that will be used in the JSON object.
      Default:
      ""
    • formatterMethod

      String formatterMethod

      Sets the name of the data formatter method.

      Here, a method can be specified that exists in the source class, is public, and has a single parameter, and is an Object type. The specified method has to return with a String type. This will be placed in the JSON object. When the method is called, the parameter will be the original field value.

      Returns:
      The formatter method name, that converts the value to text.
      Default:
      ""