This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
v3.1.0
What's New?
The JsonInput
and JsonOutput
traits are consolidated in JsonAdapter
.
import javax.json.{ JsonObject, JsonValue }
import little.json.{ Json, JsonAdapter }
import little.json.Implicits._
case class User(id: Int, name: String)
implicit object UserAdapter extends JsonAdapter[User] {
// Define how to read User from JsonValue
def reading(json: JsonValue): User =
json.asInstanceOf[JsonObject] match {
case obj => User(obj.getInt("id"), obj.getString("name"))
}
// Define how to write User to JsonValue
def writing(user: User): JsonValue =
Json.obj("id" -> user.id, "name" -> user.name)
}
// Write User to JsonValue
val json = Json.toJson(User(0, "root"))
// Read User from JsonValue
val user = json.as[User]