Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

@Retention(CLASS) @Target({FIELD, PARAMETER})

public @interface JsonProperty

Names a field in the JSON form, and says how a body may spell it.

The default JSON key is the field name; value lets a field map to snake_case or any other spelling without touching the Java identifier. aliases are further names a body may use for the same member – an old spelling a client still sends – and are only ever read: the value is always written under value. required makes a body that leaves the member out a refused body, naming the member; an explicit null is still a value, so it is accepted (and refused for a primitive, which cannot hold it).

On a parameter of a JsonCreator constructor or factory it names the member that argument is read from, since a compiled class does not keep its parameter names.

The server’s generated codecs read it too, so a class shared between an app and its backend has one JSON form on both sides.

Methods

public abstract String value() default ""The JSON key; empty for the field’s own name.
public abstract String[] aliases() default {}Other keys a body may carry the value under.
public abstract boolean required() default falseWhether a body that leaves the member out is refused.

Method details

value

public abstract String value() default ""
The JSON key; empty for the field’s own name.

aliases

public abstract String[] aliases() default {}
Other keys a body may carry the value under. Read only, never written.

required

public abstract boolean required() default false
Whether a body that leaves the member out is refused.