Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

[summary] using Scala to realize the conversion between Json and Case Class

Shulou Source: shulou.com Published: 2022-06-03 08:02:16 09月30日 Update

import org.json4s.native.Serialization. {read, write}object Json2CaseClass extends App { implicit val formats = org.json4s.DefaultFormats case class Class(_name:String, students: List[Student]) case class Student(sid:String, _name:String) val s = "{\"_name\":\"Class1\",\"students\":[{\"sid\":\"1\",\"_name\":\" Xiao Ming\"},{\"sid\":\"1\",\"_name\":\" Xiao Wang\"}]} val jazz:Class = read[Class](s) println(clazz) println(write(clazz))} org.json4s json4s-native_2.10 3.2.11 ${pkg}

Code Engineering: github.com/chocolateBlack/LearningSpark/commit/3c56dd2c89c83b99fb9b3de6d563065279ca2a0e

Tags: Code Engineering Xiao Ming Xiao Wang Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB MySQL OPPO Reno Apple