Skip to content

Commit

Permalink
support jackson annotation 'JsonAnyGetter', alibaba#136
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 4, 2022
1 parent 3448376 commit 946e69e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ public void getFieldInfo(FieldInfo fieldInfo, Class objectClass, Method method)
case "com.fasterxml.jackson.annotation.JsonIgnore":
fieldInfo.ignore = true;
break;
case "com.fasterxml.jackson.annotation.JsonAnyGetter":
fieldInfo.format = "unwrapped";
break;
case "com.alibaba.fastjson.annotation.JSONField":
processJSONField1x(fieldInfo, annotation);
break;
Expand Down Expand Up @@ -545,6 +548,9 @@ private void processAnnotation(FieldInfo fieldInfo, Annotation[] annotations) {
case "com.fasterxml.jackson.annotation.JsonIgnore":
fieldInfo.ignore = true;
break;
case "com.fasterxml.jackson.annotation.JsonAnyGetter":
fieldInfo.format = "unwrapped";
break;
case "com.alibaba.fastjson.annotation.JSONField":
processJSONField1x(fieldInfo, annotation);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public void getFieldInfo(FieldInfo fieldInfo, Class objectType, Field field) {
case "com.fasterxml.jackson.annotation.JsonIgnore":
fieldInfo.ignore = true;
break;
case "com.fasterxml.jackson.annotation.JsonAnyGetter":
fieldInfo.format = "unwrapped";
break;
case "com.fasterxml.jackson.annotation.JsonValue":
fieldInfo.features |= FieldInfo.VALUE_MASK;
break;
Expand Down Expand Up @@ -426,6 +429,9 @@ public void getFieldInfo(FieldInfo fieldInfo, Class objectClass, Method method)
case "com.fasterxml.jackson.annotation.JsonIgnore":
fieldInfo.ignore = true;
break;
case "com.fasterxml.jackson.annotation.JsonAnyGetter":
fieldInfo.format = "unwrapped";
break;
case "com.alibaba.fastjson.annotation.JSONField":
processJSONField1x(fieldInfo, annotation);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.alibaba.fastjson2.jackson_support;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class JacksonJsonAnyGetterTest {
@Test
public void test() {
ExtendableBean bean = new ExtendableBean("My bean");
bean.properties.put("attr1", "val1");
assertEquals("{\"name\":\"My bean\",\"attr1\":\"val1\"}", JSON.toJSONString(bean));
}

public static class ExtendableBean {
public String name;
private Map<String, String> properties = new HashMap<>();

public ExtendableBean(String name) {
this.name = name;
}

@JsonAnyGetter
public Map<String, String> getProperties() {
return properties;
}

}
}

0 comments on commit 946e69e

Please sign in to comment.