Skip to content

Java 8: Support for serializing and deserializing immutable objects without annotations. #399

@lpandzic

Description

@lpandzic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions