Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Support @JsonSetter annotation #2643

Closed
jorgerod opened this issue May 29, 2024 · 3 comments
Closed

[BUG] Support @JsonSetter annotation #2643

jorgerod opened this issue May 29, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@jorgerod
Copy link

Hi

We are testing FastJson2 in a spring-boot based application and we have a DTO with the @JsonSetter annotation and it is being ignored.

import static org.assertj.core.api.Assertions.assertThat;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

public class JsonSetterTest {

  @Test
  public void testJsonSetter() throws Exception {

    // given
    final String json = "{ \"department\": \"IT\" }";

    // when
    final ObjectMapper mapper = new ObjectMapper();
    final JsonSetterDTO jackson = mapper.readValue(json, JsonSetterDTO.class);

    final JsonSetterDTO fastJson2 = JSON.parseObject(json, JsonSetterDTO.class);

    // then
    assertThat(jackson.getDept()).isEqualTo(fastJson2.getDept());
  }

  static class JsonSetterDTO {

    @JsonSetter("department")
    String dept;

    public String getDept() {
      return this.dept;
    }

    public void setDept(final String dept) {
      this.dept = dept;
    }
  }
}

Result jackson

jackson = {JsonSetterTest$JsonSetterDTO@2462} 
 dept = "IT"

Result fastjson2

fastJson2 = {JsonSetterTest$JsonSetterDTO@2463} 
 dept = null

Thank you very much

@jorgerod jorgerod added the bug Something isn't working label May 29, 2024
@wenshao wenshao added this to the 2.0.51 milestone May 29, 2024
@wenshao
Copy link
Member

wenshao commented May 29, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.51-SNAPSHOT/

The BUG has been fixed. Please help verify it with version 2.0.51-SNAPSHOT

@jorgerod
Copy link
Author

Fixed! Thank you very much

@wenshao
Copy link
Member

wenshao commented Jun 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants