Skip to content
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

启用WriteClassName后parse原生类型错误 #288

Closed
TsungFang opened this issue Jan 29, 2015 · 1 comment
Closed

启用WriteClassName后parse原生类型错误 #288

TsungFang opened this issue Jan 29, 2015 · 1 comment

Comments

@TsungFang
Copy link

测试例子

系列化对象:

package xx;
public class TUser implements Serializable {
    public long id;
}
//禁用asm(在android下使用),启用asm则没问题。
SerializeConfig.getGlobalInstance().setAsmEnable(false);
String json=JSON.toJSONString(user,SerializerFeature.WriteClassName);
//输出{"@type":"xx.TUser","id":0L}
System.out.println(json);
//下面反系列化错误:com.alibaba.fastjson.JSONException: unclosed.str
//原因:id带L后缀
user=(TUser)JSON.parse(json);

bug源:JavaBeanSerializer#createFieldSerializer

if (clazz == Number.class) {
    return new NumberFieldSerializer(fieldInfo);
}

建议改为

if (clazz == Number.class || clazz == long.class || clazz == int.class  
    || clazz == float.class || clazz == double.class  
    || clazz == short.class || clazz == byte.class) {  
    return new NumberFieldSerializer(fieldInfo);  
} 
wenshao added a commit that referenced this issue Apr 13, 2016
@wenshao
Copy link
Member

wenshao commented Apr 13, 2016

问题已经修复,谢谢反馈

@wenshao wenshao closed this as completed Apr 13, 2016
wenshao added a commit that referenced this issue Apr 13, 2016
wenshao added a commit that referenced this issue Jul 17, 2019
asa1997 pushed a commit to Be-Secure/fastjson that referenced this issue Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants