Annotation Interface SerializedNames


@Beta @Target(METHOD) @Retention(RUNTIME) public @interface SerializedNames
This annotation identifies the canonical factory method on an AutoValue type used for json. It also dictates the serialized naming convention of the fields. This is required as there's currently no way to add annotations to the fields generated by AutoValue.

Example:

@AutoValue class Resource {
   abstract String id();
   @Nullable abstract Map<String, String> metadata();

   @SerializedNames({ "Id", "Metadata" }) // Note case format is controlled here!
   static Resource create(String id, Map<String, String> metadata) {
     return new AutoValue_Resource(id, metadata);
   }
 }
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Ordered values that dictate the naming convention for serialization.
  • Element Details

    • value

      String[] value
      Ordered values that dictate the naming convention for serialization.

      Note

      The order of these names must exactly match the factory method parameters and also match the order of the auto-value constructor parameters.