To serialize/deserialize immutable objects currently you have to add annotations like this:
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;
}
}
One obvious downside to this appcorach is that it adds complexity and pollutes the source code.
This can be solved by using the new API for formal parameters names retrieval in Java 8.
To pick the constructor following strategies could be used:
- @JsonCreator for explicit declaration
- implicitly reasonable default should be used such as constructor with longest parameter list.