Skip to content

[BUG] @JsonUnwrapped加在方法上时未生效  #2846

@liuzhengyang

Description

@liuzhengyang

问题描述

@JsonUnwrapped加在方法上时未生效

环境信息

请填写以下信息:

  • OS信息: mac
  • JDK信息:jdk17
  • 版本信息:Fastjson2 2.0.52

重现步骤

可复现代码

public class FastJsonTest {

    @Test
    public void testFastJson() throws Exception {
        CombineView combineView = new CombineView();
        String jacksonResult = new ObjectMapper().writeValueAsString(combineView);
        String fastjsonResult = JSON.toJSONString(new CombineView());
        Assert.assertEquals(jacksonResult, fastjsonResult);
    }

    static class CombineView {
        @JsonUnwrapped
        public View1 author() {
            return new View1();
        }
    }

    static class View1 {
        public String getAuthorName() {
            return "name";
        }
    }
}

结果

org.junit.ComparisonFailure: 
Expected :{"authorName":"name"}
Actual   :{}

期待的正确结果

正确处理方法上的@JsonUnwrapped,兼容jackson

相关日志输出

org.junit.ComparisonFailure: 
Expected :{"authorName":"name"}
Actual   :{}

附加信息

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixed

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions