-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION]使用parseObject反序列化一个类,类中包含一个枚举类,会出现null的情况,请问该怎么解决这个问题? #2239
Comments
空字符串会当做空值处理 |
我想问,如果出现null,能否指定一个初始值?该如何指定?避免后续方法出现问题 |
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.47-SNAPSHOT/ @Test
public void test() {
assertEquals(Type.NONE, JSON.parseObject("{}", Bean.class).type);
assertEquals(Type.NONE, JSON.parseObject("{\"type\":null}", Bean.class).type);
assertEquals(Type.NONE, JSON.parseObject("{\"type\":\"\"}", Bean.class).type);
}
public static class Bean {
@JSONField(defaultValue = "NONE")
public Type type;
}
public enum Type {
NONE, ONE, TWO
} |
能达到需求,但需要将属性从private改成public才可以. test方法中仅保留 执行后就提示如下 com.alibaba.fastjson2.JSONException: illegal defaultValue : NONE, class com.gf.fastjson2.FastJson2Test$Type
|
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.47-SNAPSHOT/ |
问题已解决! |
请描述您的问题
询问有关本项目的使用和其他方面的相关问题。
结果如图
The text was updated successfully, but these errors were encountered: