-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix create error for empty EnumSet and EnumMap for issue #2423
- Loading branch information
1 parent
deedf37
commit 5612e15
Showing
3 changed files
with
56 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
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
37 changes: 37 additions & 0 deletions
37
core/src/test/java/com/alibaba/fastjson2/issues_2400/Issue2423.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,37 @@ | ||
package com.alibaba.fastjson2.issues_2400; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.EnumMap; | ||
import java.util.EnumSet; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class Issue2423 { | ||
@Test | ||
void test() { | ||
Bean bean = new Bean(); | ||
|
||
String jsonStr = com.alibaba.fastjson.JSON.toJSONString(bean); | ||
Bean object = JSON.parseObject(jsonStr, Bean.class); | ||
assertTrue(object.getSet().isEmpty()); | ||
assertTrue(object.getMap().isEmpty()); | ||
assertEquals(bean, object); | ||
|
||
jsonStr = com.alibaba.fastjson2.JSON.toJSONString(bean); | ||
object = com.alibaba.fastjson2.JSON.parseObject(jsonStr, Bean.class); | ||
assertTrue(object.getSet().isEmpty()); | ||
assertTrue(object.getMap().isEmpty()); | ||
assertEquals(bean, object); | ||
} | ||
|
||
@Data | ||
static class Bean { | ||
private EnumSet<TimeUnit> set = EnumSet.noneOf(TimeUnit.class); | ||
private EnumMap<TimeUnit, Integer> map = new EnumMap<>(TimeUnit.class); | ||
} | ||
} |