Search code examples
javajsonjava-17

How can we provide Jackson annotations for java 17 record class


How can we create add field level annotations for java 17 record class?

record Rectangle(double length, double width) { }

Solution

  • yes we can use field level annotations (annotation with @Target(ElementType.FIELD) in the defination.

    @JsonInclude(Include.NON_NULL)
    record Rectangle(
        @JsonProperty("lengthAlias") double length,
        double width) { }