简体   繁体   中英

Deserialize NaN, Infinity using Json4s

Need to convert NaN in Json(as it is not JSON) to Double in Json4s without using jackson.

For example, I am having following JSON:

{ "a": NaN }

I need to parse above json using JSON4S.

Can we write any deserializer if possible for this?

You can achieve this from the version 3.6.7 :

import org.json4s._
import org.json4s.native.JsonMethods._

def main(args: Array[String]): Unit = {
  val json = """{"a": "NaN"}"""
  println(parse(json))
 // Displays
 // JObject(List((a,JString(NaN))))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM