fastjson 序列化scala.collection.mutable.Map转Json不能实现,版本1.2.58

zaq34kh6  于 2021-11-27  发布在  Java
关注(0)|答案(5)|浏览(318)

val del = Map("name" -> "bame" ) val jsonStr = JSON.toJSONString(del, SerializerFeature.PrettyFormat) println(jsonStr)

输出:
{ "empty":false, "sizeMapDefined":false, "traversableAgain":true }

tzdcorbm

tzdcorbm1#

@HenryBao91 As work-around you can use jsoniter-scala for that instead.
It is one of the most efficient Scala parser which supports all kinds of Scala collections from the standard library and can be easily extended for a custom one.

vohkndzv

vohkndzv2#

@plokhotnyuk Thank you very much.I started with json4s, and then I learned that fastjson has very strong performance, much higher than json4s, so I started trying to use fastjson. So, is the jsoniter-scala you mentioned also a popular high-performance JSON format processing library?

ghhkc1vu

ghhkc1vu3#

@HenryBao91 I should have to put a disclaimer that I have contributed to jsoniter-scala a lot.

In my early Scala days 8 years ago I used json4s too, but now nobody cares to fix security issues for it.

The 1st version of jsoniter-scala was released ~1.5 year ago and now it is gaining popularity attracting users by handy usage, safety, and performance.

One of the key difference from other JSON libraries for Scala: almost all bugs were fixed with a subsequent release in a term of couple days after reporting.

Bellow are charts from the Maven Central statistics:

As far as I understand, fastjson mostly targeted on Java users and its maintainers can be interested to bring some performance tricks from jsoniter-scala to them. It can be faster parsing and serialization for floats and doubles primitives, BigInteger, BigDecimal, and java.time.* classes, etc.

eni9jsuy

eni9jsuy4#

@plokhotnyuk I'm really honored to have your detailed answer. I'm not particularly familiar with Scala because I've only been in touch with Scala for a short time. I do find that many examples of fastjson applications on the Internet are on java. Finally, thank you very much for your valuable help.

pxyaymoc

pxyaymoc5#

可以考虑一下转为java.util.map然后用parse,自己估算一下对性能的压力

相关问题