forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support jackson annotation 'JsonAnyGetter', alibaba#136
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/test/java/com/alibaba/fastjson2/jackson_support/JacksonJsonAnyGetterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |