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.
Source: stackoverflow.com
Related Query
- Spray json format for Unit type
- Play Scala No Json deserializer found for type (String, String). Try to implement an implicit Reads or Format for this type
- No Json serializer found for type Seq[(String, String)]. Try to implement an implicit Writes or Format for this type
- (Play 2.5) How do you define json format for type alias of an Option?
- How to implement custom deserializer for type Boolean in spray json
- scala read/write format for json with Type
- No Json serializer found for type akka.http.scaladsl.model.HttpResponse.Try to implement an implicit Writes or Format for this type
- Get a Json format for a Seq of a generic type
- Scala : No Json serializer found for type Object. Try to implement an implicit Writes or Format for this type
- Should I use Unit or leave out the return type for my scala method?
- Noise free JSON format for sealed traits with Play 2.2 library
- What special rules does the scala compiler have for the unit type within the type system
- No Json serializer as JsObject found for type play.api.libs.json.JsObject
- Why is the error "Unable to find encoder for type stored in a Dataset" when encoding JSON using case classes?
- How do I write a JSON Format for an object in the Java library that doesn't have an apply method?
- Play Framework JSON Format for Case Objects
- No Json deserializer found for type Option[reactivemongo.bson.BSONObjectID]
- Play / Scala JSON Format for Either
- No Json deserializer found for type java.util.Date
- Play2 does not find my implicit Reads or Format for JSON
- create json representation for decimal logical type and byte types for avro schema
- Spray is rejecting my request for the wrong reason (405 but should be 400) when a query parameter on a PUT is the wrong type
- how do i convert json with mixed type values to json with scala and json spray
- Scala Play Json Format for Map[Locale, String]
- Scala Play - How to format Generics for JSON conversion
- How to define a JSON format for an object with nested generic types?
- Is it OK to just use POST method and JSON format for a REST-like API in Scala/Play
- scala play json reads for a seal trait or enum type object
- Defining `Reads` for JSON Set Type
- No Json deserializer found for type List[(java.util.UUID, String, String, String, Int, Int, Int, Int, java.sql.Timestamp)]
More Query from same tag
- How to import package into Scala REPL?
- Play framework action response delayed when creating multiple futures
- Apart from macro annotations, what macro creation methods avoid immediate type checking?
- MonotonicallyIncreasingId output widely variable
- value of case class parameter is not a member of Serializable
- Is this the proper way to initialize null references in Scala?
- How do you do dependency injection with the Cake pattern without hardcoding?
- Filter Flink tuples
- MinMax transformation on dataframe using Scala
- Scala - REPL - Issue with quoted named variable
- Spark Dataframe GroupBy & complex case statement derivation
- Spark 1.6 dependencies cross compiled with scala 2.11.0
- FileNotFoundException when submitting to Spark Cluster
- scala spark partitionby and get current partition name
- How do I change this implementation to use single synchronization block instead of multiple?
- Play Framework for Scala - RESTful Web Service
- How to properly create a tree in scala
- For loop issue in scala spark case
- Spark executor is throwing error "java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver"
- Integer to Binary in scala
- ScalaMock: Can't handle methods with more than 22 parameters (yet)
- Spark-Scala Invalid dependency while loading class file
- Pattern matching lists of certain size or greater/less
- Spark Streaming Application not running jobs concurrently
- Does sbaz work with Scala 2.9.1.final?
- def macro inside case statement
- How to call super method when overriding a method through a trait
- Difference between { zip map } and { flatMap map } in Future of Scala
- Confused how to set up a multi-project sbt project
- @tailrec annotated method contains a recursive call not in tail position