diff options
Diffstat (limited to 'src/main/scala/cc/spray/json/JsValue.scala')
-rw-r--r-- | src/main/scala/cc/spray/json/JsValue.scala | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/main/scala/cc/spray/json/JsValue.scala b/src/main/scala/cc/spray/json/JsValue.scala index cc1af91..f4dbf91 100644 --- a/src/main/scala/cc/spray/json/JsValue.scala +++ b/src/main/scala/cc/spray/json/JsValue.scala @@ -18,7 +18,9 @@ package cc.spray.json -import collection.mutable.ListBuffer +import collection.mutable.{LinkedHashMap, ListBuffer} +import collection.immutable.ListMap + /** * The general type of a JSON AST node. @@ -37,23 +39,14 @@ sealed trait JsValue { /** * A JSON object. */ -case class JsObject(fields: List[JsField]) extends JsValue { - lazy val asMap: Map[String, JsValue] = { - val b = Map.newBuilder[String, JsValue] - for (JsField(name, value) <- fields) b += ((name, value)) - b.result() - } -} +case class JsObject(fields: Map[String, JsValue]) extends JsValue object JsObject { - def apply(members: JsField*) = new JsObject(members.toList) + // we use a ListMap in order to preserve the field order + def apply(members: JsField*) = new JsObject(ListMap(members: _*)) + def apply(members: List[JsField]) = new JsObject(ListMap(members: _*)) } /** - * The members/fields of a JSON object. - */ -case class JsField(name: String, value: JsValue) extends JsValue - -/** * A JSON array. */ case class JsArray(elements: List[JsValue]) extends JsValue |