Annotation Type JsonFormat


@Retention(CLASS) @Target(FIELD) public @interface JsonFormat

Picks the JSON shape a date or number field is written in.

  • A java.util.Date is milliseconds since the epoch by default. With JsonFormat.Shape.STRING it is an ISO-8601 instant in UTC, 2026-10-25T08:30:00.000Z.
  • A number is a JSON number by default. With JsonFormat.Shape.STRING it is the same digits in quotes -- what a JavaScript client needs for a long past 2^53, which its numbers cannot hold exactly.

Reading accepts either shape whatever the annotation says, so a field can change its format without breaking the clients that still send the old one. Any other combination is refused by the build.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    A JSON shape for a scalar value.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The shape the value is written in.
  • Element Details