Skip to content

Commit

Permalink
fix JsonFraming to accept multiple top-level arrays (akka#26098) (akk…
Browse files Browse the repository at this point in the history
  • Loading branch information
shkoder committed Sep 24, 2019
1 parent cb18588 commit 4641589
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Expand Up @@ -44,6 +44,30 @@ class JsonFramingSpec extends AkkaSpec {
"""{ "name" : "jack" }""")
}

"parse multiple arrays" in {
val input1 =
"""
|[
| { "name" : "john" }
|]
|""".stripMargin

val input2 =
"""
|[
| { "name" : "jack" }
|]
|""".stripMargin

val result = Source(List(ByteString(input1), ByteString(input2)))
.via(JsonFraming.objectScanner(Int.MaxValue))
.runFold(Seq.empty[String]) {
case (acc, entry) => acc ++ Seq(entry.utf8String)
}

result.futureValue shouldBe Seq("""{ "name" : "john" }""", """{ "name" : "jack" }""")
}

"emit single json element from string" in {
val input =
"""| { "name": "john" }
Expand Down
Expand Up @@ -116,7 +116,8 @@ import scala.annotation.switch
trimFront += 1
} else if (input == SquareBraceEnd && outsideObject) {
// outer array completed!
pos = -1
pos += 1
trimFront += 1
} else if (input == Comma && outsideObject) {
// do nothing
pos += 1
Expand All @@ -137,9 +138,7 @@ import scala.annotation.switch
isStartOfEscapeSequence = false
depth -= 1
pos += 1
if (depth == 0) {
completedObject = true
}
if (depth == 0) completedObject = true
} else if (isWhitespace(input) && !inStringExpression) {
pos += 1
if (depth == 0) trimFront += 1
Expand Down

0 comments on commit 4641589

Please sign in to comment.