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

object Json

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)
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Json
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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 arr(values: JsonValue*): JsonArray

    Creates JsonArray from list of values.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  7. def createArrayBuilder(): JsonArrayBuilder

    Creates JsonArrayBuilder.

  8. def createGenerator(writer: Writer, prettyPrinting: Boolean): JsonGenerator

    Creates JsonGenerator with given writer.

    Creates JsonGenerator with given writer.

    writer

    writer to which JSON is written

    prettyPrinting

    specifies whether JSON output should be beautified

  9. def createGenerator(writer: Writer): JsonGenerator

    Creates JsonGenerator with given writer.

  10. def createGenerator(out: OutputStream, prettyPrinting: Boolean): JsonGenerator

    Creates JsonGenerator with given output stream.

    Creates JsonGenerator with given output stream.

    out

    output stream to which JSON is written

    prettyPrinting

    specifies whether JSON output should be beautified

  11. def createGenerator(out: OutputStream): JsonGenerator

    Creates JsonGenerator with given output stream.

  12. def createObjectBuilder(): JsonObjectBuilder

    Creates JsonObjectBuilder.

  13. def createParser(reader: Reader): JsonParser

    Creates JsonParser with given reader.

  14. def createParser(in: InputStream): JsonParser

    Creates JsonParser with given input stream.

  15. def createReader(reader: Reader): JsonReader

    Creates JsonReader with given reader.

  16. def createReader(in: InputStream): JsonReader

    Creates JsonReader with given input stream.

  17. def createWriter(writer: Writer, prettyPrinting: Boolean): JsonWriter

    Creates JsonWriter with given writer.

    Creates JsonWriter with given writer.

    writer

    writer to which JSON is written

    prettyPrinting

    specifies whether JSON output should be beautified

  18. def createWriter(writer: Writer): JsonWriter

    Creates JsonWriter with given writer.

  19. def createWriter(out: OutputStream, prettyPrinting: Boolean): JsonWriter

    Creates JsonWriter with given output stream.

    Creates JsonWriter with given output stream.

    out

    output stream to which JSON is written

    prettyPrinting

    specifies whether JSON output should be beautified

  20. def createWriter(out: OutputStream): JsonWriter

    Creates JsonWriter with given output stream.

  21. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  23. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  24. def fromJson[T](json: JsonValue)(implicit input: JsonInput[T]): T

    Converts JsonValue to T value.

  25. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  26. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  27. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  28. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  29. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  30. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  31. def obj(fields: (String, JsonValue)*): JsonObject

    Creates JsonObject from list of fields.

  32. def parse(file: File): JsonStructure

    Parses text from given file to JsonStructure.

  33. def parse(reader: Reader): JsonStructure

    Parses text from given reader to JsonStructure.

  34. def parse(in: InputStream): JsonStructure

    Parses text from given input stream to JsonStructure.

  35. def parse(text: String): JsonStructure

    Parses given text to JsonStructure.

  36. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  37. def toJson[T](value: T)(implicit output: JsonOutput[T]): JsonValue

    Converts T value to JsonValue.

  38. def toString(): String
    Definition Classes
    AnyRef → Any
  39. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped