score:2

Accepted answer

to my knowledge no predefined json format for unit exists. but you can write your own json format:

import spray.json._
import defaultjsonprotocol._

implicit object unitjsonformat extends jsonformat[unit] {
  def write(u: unit) = jsobject()
  def read(value: jsvalue): unit = value match {
      case jsobject(fields) if fields.isempty => unit
  }
}

using it:

scala> println("").tojson

res0: spray.json.jsvalue = {}

scala> res0.convertto[unit]

scala>

update: i'm not sure what you are expecting the json to look like for unit, please clarify.

score:0

i came to this question and later found out that spray provides jsonformats for the most important scala types(e.g. int, long, float, double, byte, short, bigdecimal, bigint, unit, boolean, char, string and symbol) in trait basicformats.

you can simply mixin basicformats and it will work.


Related Query

More Query from same tag