From 24af701d7e3bce6f72bb8b2f12c6099f3d85403f Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 4 Oct 2011 09:40:35 +0200 Subject: Improve some scaladoc comments --- src/main/scala/cc/spray/json/AdditionalFormats.scala | 9 +++++++++ src/main/scala/cc/spray/json/JsValue.scala | 2 +- src/main/scala/cc/spray/json/ProductFormats.scala | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src/main') 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 => -- cgit v1.2.3