Skip to content

[BUG] Jackson's @JsonProperty on methods is being ignored in record types #3893

@JJag

Description

@JJag

Problem Description

Methods annotated with @com.fasterxml.jackson.annotation.JsonProperty are ignored on record types.
It worked as expected up to version 2.58.
It works as expected on class types.

Environment

  • OS: macOS 26.1
  • JDK: openjdk 21.0.2
  • fastjson2: 2.60

How to reproduce the problem

Add following libraries to classpath:

com.fasterxml.jackson.core:jackson-annotations:2.20
com.alibaba.fastjson2:fastjson2:2.0.60

Minimal reproducer:

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;

record Foo(int x) {

  @JsonProperty
  public int y() {
    return 42;
  }

  public static void main(String[] args) {
    Foo foo = new Foo(5);
    Object json = JSON.toJSON(foo);
    System.out.println(json);
  }
}

Expected output

{"x":5,"y":42}

Actual output

{"x":5}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions