org.json4s
Type members
Classlikes
Function to extract values from JSON AST using case classes.
Function to extract values from JSON AST using case classes.
See: ExtractionExamples.scala
Serializer which serializes all fields of a class too.
Serializer which serializes all fields of a class too.
Serialization can be intercepted by giving two optional PartialFunctions as constructor parameters:
FieldSerializer[WildDog]( renameTo("name", "animalname") orElse ignore("owner"), renameFrom("animalname", "name") )
The third optional parameter "includeLazyVal" determines if serializer will serialize/deserialize lazy val fields or not.
- Companion
- object
Formats to use when converting JSON. Formats are usually configured by using an implicit parameter:
Formats to use when converting JSON. Formats are usually configured by using an implicit parameter:
implicit val formats: Formats = org.json4s.DefaultFormats
- Companion
- object
Use a map of keys as type hints. Values may not be mapped by multiple keys
Use a map of keys as type hints. Values may not be mapped by multiple keys
Type hints can be used to alter the default conversion rules when converting Scala instances into JSON and vice versa. Type hints must be used when converting class which is not supported by default (for instance when class is not a case class).
Type hints can be used to alter the default conversion rules when converting Scala instances into JSON and vice versa. Type hints must be used when converting class which is not supported by default (for instance when class is not a case class).
Example:
class DateTime(val time: Long) val hints = new ShortTypeHints(classOf[DateTime] :: Nil) { override def serialize: PartialFunction[Any, JObject] = { case t: DateTime => JObject(JField("t", JInt(t.time)) :: Nil) } override def deserialize: PartialFunction[(String, JObject), Any] = { case ("DateTime", JObject(JField("t", JInt(t)) :: Nil)) => new DateTime(t.longValue) } } implicit val formats: Formats = DefaultFormats.withHints(hints)