summaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authorMathias <mathias@spray.cc>2011-10-04 09:40:35 +0200
committerMathias <mathias@spray.cc>2011-10-04 09:45:46 +0200
commit24af701d7e3bce6f72bb8b2f12c6099f3d85403f (patch)
treebd917afb03aed008edaf55058f65e79b0cfea118 /src/main/scala
parent758e17d8c780ab44befc26a18344367f70334c56 (diff)
downloadspray-json-24af701d7e3bce6f72bb8b2f12c6099f3d85403f.tar.gz
spray-json-24af701d7e3bce6f72bb8b2f12c6099f3d85403f.tar.bz2
spray-json-24af701d7e3bce6f72bb8b2f12c6099f3d85403f.zip
Improve some scaladoc comments
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/cc/spray/json/AdditionalFormats.scala9
-rw-r--r--src/main/scala/cc/spray/json/JsValue.scala2
-rw-r--r--src/main/scala/cc/spray/json/ProductFormats.scala7
3 files changed, 17 insertions, 1 deletions
diff --git a/src/main/scala/cc/spray/json/AdditionalFormats.scala b/src/main/scala/cc/spray/json/AdditionalFormats.scala
index e8b59c7..db9d3ba 100644
--- a/src/main/scala/cc/spray/json/AdditionalFormats.scala
+++ b/src/main/scala/cc/spray/json/AdditionalFormats.scala
@@ -27,17 +27,26 @@ trait AdditionalFormats {
def read(value: JsValue) = value
}
+ /**
+ * Constructs a JsonFormat from its two parts, JsonReader and JsonWriter.
+ */
def jsonFormat[T](reader: JsonReader[T], writer: JsonWriter[T]) = new JsonFormat[T] {
def write(obj: T) = writer.write(obj)
def read(json: JsValue) = reader.read(json)
}
+ /**
+ * Turns a JsonWriter into a JsonFormat that throws an UnsupportedOperationException for reads.
+ */
def lift[T](writer :JsonWriter[T]) = new JsonFormat[T] {
def write(obj: T): JsValue = writer.write(obj)
def read(value: JsValue) =
throw new UnsupportedOperationException("JsonReader implementation missing")
}
+ /**
+ * Turns a JsonReader into a JsonFormat that throws an UnsupportedOperationException for writes.
+ */
def lift[T <: AnyRef](reader :JsonReader[T]) = new JsonFormat[T] {
def write(obj: T): JsValue =
throw new UnsupportedOperationException("No JsonWriter[" + obj.getClass + "] available")
diff --git a/src/main/scala/cc/spray/json/JsValue.scala b/src/main/scala/cc/spray/json/JsValue.scala
index a02de0f..86dbb06 100644
--- a/src/main/scala/cc/spray/json/JsValue.scala
+++ b/src/main/scala/cc/spray/json/JsValue.scala
@@ -55,7 +55,7 @@ object JsValue {
case x: collection.Seq[_] => JsArray(x.toList.map(JsValue.apply))
case x => throw new IllegalArgumentException(x.toString + " cannot be converted to a JsValue")
}
-
+
private def fromSeq(seq: Iterable[(_, _)]) = {
val list = ListBuffer.empty[JsField]
seq.foreach {
diff --git a/src/main/scala/cc/spray/json/ProductFormats.scala b/src/main/scala/cc/spray/json/ProductFormats.scala
index ec58d22..d0263c8 100644
--- a/src/main/scala/cc/spray/json/ProductFormats.scala
+++ b/src/main/scala/cc/spray/json/ProductFormats.scala
@@ -422,6 +422,13 @@ trait ProductFormats {
}
}
+/**
+ * This trait supplies an alternative rendering mode for optional case class members.
+ * Normally optional members that are undefined (`None`) are not rendered at all.
+ * By mixing in this trait into your custom JsonProtocol you can enforce the rendering of undefined members as `null`.
+ * (Note that this only affect JSON writing, spray-json will always read missing optional members as well as `null`
+ * optional members as `None`.)
+ */
trait NullOptions extends ProductFormats {
this: StandardFormats =>