package json
- Alphabetic
- Public
- All
Type Members
-
trait
ArrayBuilderCompanion[T] extends AnyRef
Adds value to JsonArrayBuilder.
Adds value to JsonArrayBuilder.
- See also
-
trait
ArrayContextWriter[T] extends AnyRef
Writes value in array context to JsonGenerator.
Writes value in array context to JsonGenerator.
- See also
-
trait
BuilderCompanion[T] extends ArrayBuilderCompanion[T] with ObjectBuilderCompanion[T]
Adds value to builder.
-
trait
ContextWriter[T] extends ArrayContextWriter[T] with ObjectContextWriter[T]
Writes value to JsonGenerator.
-
trait
JsonAdapter[T] extends JsonInput[T] with JsonOutput[T]
Consolidates JsonInput and JsonOutput.
Consolidates JsonInput and JsonOutput.
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]
-
trait
JsonInput[T] extends AnyRef
Reads value of type T from JsonValue.
Reads value of type T from JsonValue.
import javax.json.JsonObject import little.json.{ Json, JsonInput } import little.json.Implicits.JsonValueType case class User(id: Int, name: String) // Define how to read User from JsonValue implicit val userInput: JsonInput[User] = { case json: JsonObject => User(json.getInt("id"), json.getString("name")) case json => throw new IllegalArgumentException("JsonObject required") } // Parse String to JsonValue val json = Json.parse("""{ "id": 0, "name": "root" }""") // Read User from JsonValue val user = json.as[User]
- See also
-
trait
JsonOutput[T] extends BuilderCompanion[T] with ContextWriter[T]
Writes value of type T to JsonValue.
Writes value of type T to JsonValue.
import little.json.{ Json, JsonOutput } import little.json.Implicits._ case class User(id: Int, name: String) // Define how to write User to JsonValue implicit val userOutput: JsonOutput[User] = { user => Json.obj("id" -> user.id, "name" -> user.name) } // Write User to JsonValue val json = Json.toJson(User(0, "root"))
- See also
-
trait
ObjectBuilderCompanion[T] extends AnyRef
Adds value to JsonObjectBuilder.
Adds value to JsonObjectBuilder.
- See also
-
trait
ObjectContextWriter[T] extends AnyRef
Writes value in object context to JsonGenerator.
Writes value in object context to JsonGenerator.
- See also
Value Members
-
object
Implicits
Provides type classes for
javax.json
and implicit implementations ofJsonOutput
andJsonInput
. -
object
Json
Provides factory methods and other utilities.
Provides factory methods and other utilities.
import javax.json.JsonObject import little.json.{ Json, JsonInput, JsonOutput } import little.json.Implicits._ case class User(id: Int, name: String) // Define how to read User from JsonValue implicit val userJsonInput: JsonInput[User] = { case json: JsonObject => User(json.getInt("id"), json.getString("name")) case json => throw new IllegalArgumentException("JsonObject required") } // Define how to write User to JsonValue implicit val userJsonOutput: JsonOutput[User] = { user => Json.obj("id" -> user.id, "name" -> user.name) } // Parse String to JsonValue val json = Json.parse("""{ "id": 0, "name": "root" }""") // Read User from JsonValue val user = json.as[User] // Write User to JsonValue val jsonToo = Json.toJson(user)