Packages

  • package root
    Definition Classes
    root
  • package little
    Definition Classes
    root
  • package json
    Definition Classes
    little
  • package rpc

    Defines API for JSON-RPC 2.0.

    Defines API for JSON-RPC 2.0.

    import little.json.{ Json, JsonOutput }
    import little.json.Implicits._
    import little.json.rpc._
    
    case class Problem(values: Int*)
    case class Answer(value: Int)
    
    // Used when creating "params" in request
    implicit val problemOutput: JsonOutput[Problem] = {
      problem => Json.toJson(problem.values)
    }
    
    // Used when creating "result" in response
    implicit val answerOutput: JsonOutput[Answer] = {
      answer => Json.obj("answer" -> answer.value)
    }
    
    val request = JsonRpcRequest(
      version = "2.0",
      id = "590d24ae-500a-486c-8d73-8035e78529bd",
      method = "sum",
      params = Problem(1, 2, 3) // Uses problemOutput
    )
    
    val response = JsonRpcResponse(
      version = request.version,
      id = request.id,
      result = request.method match {
        case "sum" =>
          // Sets result
          request.params
            .map(_.as[Array[Int]])
            .map(_.sum)
            .map(Answer(_))
            .map(JsonRpcResult(_)) // Uses answerOutput
            .get
        case name =>
          // Or sets error
          JsonRpcResult(MethodNotFound(name))
      }
    )
    Definition Classes
    json
  • ArrayBuilderCompanion
  • ArrayContextWriter
  • BuilderCompanion
  • ContextWriter
  • Implicits
  • Json
  • JsonAdapter
  • JsonInput
  • JsonOutput
  • ObjectBuilderCompanion
  • ObjectContextWriter
t

little.json

JsonAdapter

trait JsonAdapter[T] extends JsonInput[T] with JsonOutput[T]

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]
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. JsonAdapter
  2. JsonOutput
  3. ContextWriter
  4. ObjectContextWriter
  5. ArrayContextWriter
  6. BuilderCompanion
  7. ObjectBuilderCompanion
  8. ArrayBuilderCompanion
  9. JsonInput
  10. AnyRef
  11. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def reading(json: JsonValue): T

    Converts JsonValue to T value.

    Converts JsonValue to T value.

    Definition Classes
    JsonInput
  2. abstract def writing(value: T): JsonValue

    Converts T value to JsonValue.

    Converts T value to JsonValue.

    Definition Classes
    JsonOutput

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def add(name: String, value: T)(implicit builder: JsonObjectBuilder): JsonObjectBuilder

    Converts T value to JsonValue and adds it to object builder.

    Converts T value to JsonValue and adds it to object builder.

    Definition Classes
    JsonOutputObjectBuilderCompanion
  5. def add(value: T)(implicit builder: JsonArrayBuilder): JsonArrayBuilder

    Converts T value to JsonValue and adds it to array builder.

    Converts T value to JsonValue and adds it to array builder.

    Definition Classes
    JsonOutputArrayBuilderCompanion
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  22. def write(name: String, value: T)(implicit generator: JsonGenerator): JsonGenerator

    Converts T value to JsonValue and writes it to object context.

    Converts T value to JsonValue and writes it to object context.

    Definition Classes
    JsonOutputObjectContextWriter
  23. def write(value: T)(implicit generator: JsonGenerator): JsonGenerator

    Converts T value to JsonValue and writes it to array context.

    Converts T value to JsonValue and writes it to array context.

    Definition Classes
    JsonOutputArrayContextWriter

Inherited from JsonOutput[T]

Inherited from ContextWriter[T]

Inherited from ObjectContextWriter[T]

Inherited from ArrayContextWriter[T]

Inherited from BuilderCompanion[T]

Inherited from ObjectBuilderCompanion[T]

Inherited from ArrayBuilderCompanion[T]

Inherited from JsonInput[T]

Inherited from AnyRef

Inherited from Any

Ungrouped