-
Notifications
You must be signed in to change notification settings - Fork 11
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
d115575
commit 1a8ce1d
Showing
6 changed files
with
67 additions
and
53 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
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
14 changes: 14 additions & 0 deletions
14
src/main/scala/com/exasol/cloudetl/util/JsonDeserializer.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,14 @@ | ||
package com.exasol.cloudetl.util | ||
|
||
import com.fasterxml.jackson.databind.{MapperFeature, ObjectMapper} | ||
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, ScalaObjectMapper} | ||
|
||
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements")) | ||
object JsonDeserializer { | ||
lazy val mapper = new ObjectMapper with ScalaObjectMapper | ||
mapper.registerModule(DefaultScalaModule) | ||
mapper.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS) | ||
|
||
def parseJson[T: Manifest](jsonString: String): T = | ||
mapper.readValue[T](jsonString) | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/test/scala/com/exasol/cloudetl/util/JsonDeserializerTest.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,13 @@ | ||
package com.exasol.cloudetl.util | ||
|
||
import scala.collection.immutable.HashMap | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class JsonDeserializerTest extends AnyFunSuite { | ||
test("parseJson parses a String") { | ||
val jsonString = "{\"sensorId\": 17,\"currentTemperature\": 147,\"status\": \"WARN\"}" | ||
val values = JsonDeserializer.parseJson[HashMap[String, Object]](jsonString) | ||
assert(values === HashMap(("sensorId", 17), ("currentTemperature", 147), ("status", "WARN"))) | ||
} | ||
} |