-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d47cfe4
commit 25d7fe0
Showing
7 changed files
with
94 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
json/src/main/scala/io/github/agolovenko/avro/json/JsonException.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.agolovenko.avro.json | ||
|
||
import scala.util.control.NoStackTrace | ||
|
||
class JsonException(message: String, cause: Throwable = null) extends RuntimeException(message, cause) with NoStackTrace |
22 changes: 11 additions & 11 deletions
22
...lovenko/avro/json/JsonArrayIterator.scala → ...b/agolovenko/avro/json/JsonIterator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
json/src/test/scala/io/github/agolovenko/avro/json/JsonArrayIteratorSpec.scala
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
json/src/test/scala/io/github/agolovenko/avro/json/JsonIteratorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.github.agolovenko.avro.json | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
import java.io.StringReader | ||
|
||
class JsonIteratorSpec extends AnyWordSpec with Matchers { | ||
"parses json array" in { | ||
val json = | ||
""" | ||
|[ | ||
| { | ||
| "lastUpdated": "2020-04-17T19:38:47.04+00:00", | ||
| "id": "16289", | ||
| "clientId": 123, | ||
| "description": { | ||
| "type": "normal", | ||
| "text": "good one" | ||
| } | ||
| }, | ||
| { | ||
| "lastUpdated": "2020-04-17T19:38:40.04+00:00", | ||
| "id": "16288", | ||
| "clientId": 124, | ||
| "description": { | ||
| "type": "normal", | ||
| "text": "very good one" | ||
| } | ||
| } | ||
|] | ||
|""".stripMargin | ||
|
||
val it = new JsonIterator(new StringReader(json)) | ||
val jsObjects = it.toList | ||
|
||
jsObjects should have size 2 | ||
(jsObjects(1) \ "clientId").as[Int] shouldBe 124 | ||
} | ||
|
||
"parses json object" in { | ||
val json = | ||
""" | ||
| { | ||
| "lastUpdated": "2020-04-17T19:38:47.04+00:00", | ||
| "id": "16289", | ||
| "clientId": 123, | ||
| "description": { | ||
| "type": "normal", | ||
| "text": "good one" | ||
| } | ||
| } | ||
|""".stripMargin | ||
|
||
val it = new JsonIterator(new StringReader(json)) | ||
val jsObjects = it.toList | ||
|
||
jsObjects should have size 1 | ||
(jsObjects.head \ "clientId").as[Int] shouldBe 123 | ||
} | ||
|
||
"expects array of objects as input" in { | ||
an[JsonException] should be thrownBy new JsonIterator(new StringReader(" [{}, 1234]")).foreach(_ => ()) | ||
|
||
noException should be thrownBy new JsonIterator(new StringReader(" {}")).foreach(_ => ()) | ||
noException should be thrownBy new JsonIterator(new StringReader(""" [{}, {"number": 1234} ]""")).foreach(_ => ()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters