Annotation Interface JSONType


@Retention(RUNTIME) @Target(TYPE) public @interface JSONType
Generates a JSON codec for this type.

Records are the straightforward case: the components are the fields and the canonical constructor is the decoder. A class works too when it has a no-argument constructor and either public fields or setters.

Nested types need the annotation as well. The generator refuses a field whose type has no codec rather than emitting one that silently reads null, so a missing annotation is a build failure that names the field.

 @JSONType
 public record Settings(String host, int port, List<String> hosts) {}
Since:
1.0.0
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether to leave out a field holding null rather than writing it as null.
  • Element Details

    • omitNulls

      boolean omitNulls
      Whether to leave out a field holding null rather than writing it as null.
      Returns:
      whether to omit nulls
      Default:
      false