-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3172 Fix: 枚举类 ValueField 的类型为 Integer 时,无法反序列化 String 类型的值
- Loading branch information
Showing
2 changed files
with
28 additions
and
5 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
21 changes: 21 additions & 0 deletions
21
core/src/test/java/com/alibaba/fastjson2/issues_3100/Issue3172Kt.kt
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,21 @@ | ||
package com.alibaba.fastjson2.issues_3100 | ||
|
||
import com.alibaba.fastjson2.JSON | ||
import com.fasterxml.jackson.annotation.JsonValue | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
enum class UserStatus(@JsonValue val value: Int, val label: String) { | ||
NORMAL(1, "正常"), | ||
LOCKED(2, "锁定"), | ||
} | ||
|
||
class EnumTest { | ||
@Test | ||
fun testEnum() { | ||
val value = "\"2\"" | ||
val status = JSON.parseObject(value, UserStatus::class.java) | ||
println("Enum Item: $status") // null, version=2.0.53 | ||
Assertions.assertEquals(UserStatus.LOCKED, status) | ||
} | ||
} |