-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix serialize field priority, for issue #1727
- Loading branch information
Showing
2 changed files
with
79 additions
and
2 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
55 changes: 55 additions & 0 deletions
55
core/src/test/java/com/alibaba/fastjson2/issues_1700/Issue1727.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,55 @@ | ||
package com.alibaba.fastjson2.issues_1700; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import lombok.Getter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1727 { | ||
@Test | ||
public void test() { | ||
final Bean bean = new Bean(); | ||
bean.color = Color.BLUE; | ||
|
||
assertEquals("{\"color\":5}", JSON.toJSONString(bean)); | ||
} | ||
|
||
public enum Color { | ||
RED(1), | ||
YELLOW(3), | ||
BLUE(5); | ||
|
||
final Integer value; | ||
|
||
Color(Integer value) { | ||
this.value = value; | ||
} | ||
} | ||
|
||
@Getter | ||
public static class Bean { | ||
public Color color; | ||
|
||
public Integer getColor() { | ||
return color.value; | ||
} | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
final Bean1 bean = new Bean1(); | ||
bean.color = Color.BLUE; | ||
|
||
assertEquals("{\"color\":5}", JSON.toJSONString(bean)); | ||
} | ||
|
||
@Getter | ||
public static class Bean1 { | ||
public Color color; | ||
|
||
public int getColor() { | ||
return color.value; | ||
} | ||
} | ||
} |