Skip to content

Commit

Permalink
fix jackson annotation JsonUnwrapped compatible, for issue #2846
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 8, 2024
1 parent 07de7e2 commit 9728336
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
}

0 comments on commit 9728336

Please sign in to comment.