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\":\"小明\"},{\"sid\":\"1\",\"_name\":\"小王\"}]}" val clazz:Class = read[Class](s) println(clazz) println(write(clazz)) }
<dependency> <groupId>org.json4s</groupId> <artifactId>json4s-native_2.10</artifactId> <version>3.2.11</version> <scope>${pkg}</scope> </dependency>
代码工程:https://github.com/chocolateBlack/LearningSpark/commit/3c56dd2c89c83b99fb9b3de6d563065279ca2a0e
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。