www.fgks.org   »   [go: up one dir, main page]

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

ValueFilter对于ListSerializer无效 #550

Open
wangwenyou opened this issue Apr 15, 2016 · 2 comments
Open

ValueFilter对于ListSerializer无效 #550

wangwenyou opened this issue Apr 15, 2016 · 2 comments

Comments

@wangwenyou
Copy link
wangwenyou commented Apr 15, 2016

不启用BrowserCompatible,List丢失精度,使用ValueFilter来处理,但ListSerializer无视ValueFilter。
BrowserCompatible做的事太多了,影响性能。

@wenshao
Copy link
Member
wenshao commented Apr 15, 2016

为啥List会丢失精度?

@wangwenyou
Copy link
Author

抱歉,说得太简略了,是返回给前端使用的。
writeLong的判断是
if ((isEnabled(SerializerFeature.BrowserCompatible)) && (!isEnabled(SerializerFeature.WriteClassName)))
开始启用了BrowserCompatible,发现2.6M的String to JSON用了37秒,而关闭BrowserCompatible只需要几百毫秒;而且BrowserCompatible的中文转码我也不需要。
所以关闭BrowserCompatible使用ValueFilter来自己处理,但ValueFilter/NameFilter似乎是Map专用的,
JSON.toJSONString(object,new ValueFilter() {
// Write Number as String
@OverRide
public Object process(Object object, String name, Object value) {
if(value instanceof Number && !(value instanceof Integer)){
return String.valueOf(value);
}
return value;
}
},SerializerFeature.DisableCircularReferenceDetect,
// SerializerFeature.BrowserCompatible,
SerializerFeature.WriteDateUseDateFormat,
SerializerFeature.WriteMapNullValue);
}

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