日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

fastJson toJSONString注意点

發布時間:2023/12/19 javascript 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 fastJson toJSONString注意点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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時是否使用雙引號,默認為true
UseSingleQuotes使用單引號而不是雙引號,默認為false
WriteMapNullValue是否輸出值為null的字段,默認為false
WriteEnumUsingToStringEnum輸出name()或者original,默認為false
SortField按字段名稱排序后輸出。默認為false
WriteTabAsSpecial把\t做轉義輸出,默認為false
PrettyForma結果是否格式化,默認為false
WriteClassName序列化時寫入類型信息,默認為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);}

?

總結

以上是生活随笔為你收集整理的fastJson toJSONString注意点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。