广州南沙网站建设公司,企业logo设计合同,城乡住房和城乡建设部网站,服务于中小企业建网站fastJosn是阿里爸爸推出一款高性能序列化工具#xff0c;号称最快的json序列化工具。不过好像也就那样#xff0c;在量比较大的时候优势才会明显。单次序列化时间还是会达到几十毫秒的级别。
Fastjson is a Java library that can be used to convert Java Objects into the…fastJosn是阿里爸爸推出一款高性能序列化工具号称最快的json序列化工具。不过好像也就那样在量比较大的时候优势才会明显。单次序列化时间还是会达到几十毫秒的级别。
Fastjson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Fastjson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.
Fastjson Goals
Provide best performance in server side and android client.Provide simple toJSONString() and parseObject() methods to convert Java objects to JSON and vice-versa.Allow pre-existing unmodifiable objects to be converted to and from JSON.Extensive support of Java Generics.Allow custom representations for objects.Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types).
toJSONString:
使用toJSONString时有两个点需要注意
1默认情况下属性值为null的字段不会打印若需要展示需使用SerializerFeature.WRITE_MAP_NULL_FEATURES
SerializerFeature属性
名称含义QuoteFieldNames输出key时是否使用双引号,默认为trueUseSingleQuotes使用单引号而不是双引号,默认为falseWriteMapNullValue是否输出值为null的字段,默认为falseWriteEnumUsingToStringEnum输出name()或者original,默认为falseSortField按字段名称排序后输出。默认为falseWriteTabAsSpecial把\t做转义输出默认为falsePrettyForma结果是否格式化,默认为falseWriteClassName序列化时写入类型信息默认为false。反序列化是需用到
2只会打印正常类型的属性信息自定义类无法展示。 /*** This method serializes the specified object into its equivalent Json representation. Note that this method works fine if the any of the object fields are of generic type,* just the object itself should not be of a generic type. If you want to write out the object to a* {link Writer}, use {link #writeJSONString(Writer, Object, SerializerFeature[])} instead.** param object the object for which json representation is to be created setting for fastjson* return Json representation of {code object}.*/public static String toJSONString(Object object) {return toJSONString(object, emptyFilters);}