This commit is contained in:
Looly
2026-01-17 19:57:28 +08:00
parent 266cd0754c
commit a32fac8760

View File

@@ -0,0 +1,32 @@
package cn.hutool.json;
import lombok.Data;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue4214Test {
@Test
void toBeanTest(){
LicenseInfo licenseInfo = new LicenseInfo();
licenseInfo.setAuthTypeEnum(AuthTypeEnum.OFFICIAL);
String jsonStr = JSONUtil.toJsonStr(licenseInfo);
assertEquals("{\"authTypeEnum\":\"OFFICIAL\"}", jsonStr);
// 这里反序列化会报错
LicenseInfo bean = JSONUtil.toBean(jsonStr, LicenseInfo.class);
assertEquals(AuthTypeEnum.OFFICIAL, bean.getAuthTypeEnum());
}
@Data
static class LicenseInfo{
private AuthTypeEnum authTypeEnum;
}
enum AuthTypeEnum{
OFFICIAL,
SELF_BUILD
}
}