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({CONSTRUCTOR, METHOD})
public @interface JsonCreator
The constructor, or static factory method, that builds an immutable class from JSON.
A class with final fields and no constructor without arguments cannot be
filled in field by field, so its JSON is read into one local per member and
handed to this constructor at once – as a record’s canonical constructor
is. Every parameter carries JsonProperty naming the member it is read
from; a compiled class does not keep parameter names, so there is nothing
else to match them by. A member a body leaves out arrives as its type’s
default (null, 0, false) unless it is required.
@Mapped
public final class Point {
private final int x;
private final int y;
@JsonCreator
public Point(@JsonProperty("x") int x, @JsonProperty("y") int y) {
this.x = x;
this.y = y;
}
public int getX() { return x; }
public int getY() { return y; }
}
The generated code calls it directly; nothing is looked up by name.