Skip to content

Commit

Permalink
Added the ability to parse json primitives at the top level
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Rhys-Jones committed Nov 19, 2012
1 parent 3f59efc commit c8f7985
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions core/json/src/main/scala/net/liftweb/json/JsonParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ object JsonParser {
}

def newValue(v: JValue) {
vals.peek(classOf[JValue]) match {
case f: JField =>
vals.peekOption match {
case Some(f: JField) =>
vals.pop(classOf[JField])
val newField = JField(f.name, v)
val obj = vals.peek(classOf[JObject])
vals.replace(JObject(newField :: obj.obj))
case a: JArray => vals.replace(JArray(v :: a.arr))
case Some(a: JArray) => vals.replace(JArray(v :: a.arr))
case None =>
vals.push(v)
root = Some(v)
case _ => p.fail("expected field or array")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object JsonParserSpec extends Specification with JValueGen with ScalaCheck {

"Any valid json can be parsed" in {
val parsing = (json: JValue) => { parse(Printer.pretty(render(json))); true }
check(forAll(parsing))
check(forAll(genJValue)(parsing))
}

"Buffer size does not change parsing result" in {
Expand Down

1 comment on commit c8f7985

@jonifreeman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the feature change (although JSON spec does not allow primitives at top level). Two issues with this patch though:

  • Boxing to Option at parsing level must have a performance impact. That should be measured or boxing should be removed.
  • Why 'forAll(genJValue)(parsing)'

Please sign in to comment.