Lift-json extract json with 'type' field into a case class
Asked Answered
F

1

12

I am trying to extract JSON into a case class using lift-json. Here is my case class:

case class Person(name: String, age: Int)

Here is the json

{ "name": "Some Name", "age": 24, type: "Student" }

How can I extract the type field into an instance Person?

json.extract[Person]
Francois answered 18/9, 2011 at 15:35 Comment(1)
What is the error message you get? Have you tried it with: case class Person(name: String, age: Int, `type`: String). Obviously type is a reserved word in Scala, but you can work around that with back-ticks.Essential
T
20

Backticks allow you to use reserved names.

case class Person(name:String, age:Int, `type`:String)
Tetrameter answered 18/9, 2011 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.