diff --git a/core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java b/core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java index 71570be51a..af7eb4fbdd 100644 --- a/core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java +++ b/core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java @@ -1125,6 +1125,7 @@ private static boolean isJSONField(AnnotatedElement element) { case "com.fasterxml.jackson.annotation.JsonValue": case "com.fasterxml.jackson.annotation.JsonRawValue": case "com.fasterxml.jackson.annotation.JsonProperty": + case "com.fasterxml.jackson.annotation.JsonUnwrapped": if (JSONFactory.isUseJacksonAnnotation()) { return true; } diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_2800/Issue2846.java b/core/src/test/java/com/alibaba/fastjson2/issues_2800/Issue2846.java new file mode 100644 index 0000000000..ea58560bb5 --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues_2800/Issue2846.java @@ -0,0 +1,31 @@ +package com.alibaba.fastjson2.issues_2800; + +import com.alibaba.fastjson2.JSON; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Issue2846 { + @Test + public void testFastJson() throws Exception { + CombineView combineView = new CombineView(); + String jacksonResult = new ObjectMapper().writeValueAsString(combineView); + String fastjsonResult = JSON.toJSONString(new CombineView()); + assertEquals(jacksonResult, fastjsonResult); + } + + static class CombineView { + @JsonUnwrapped + public View1 author() { + return new View1(); + } + } + + static class View1 { + public String getAuthorName() { + return "name"; + } + } +}