Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 3f5d041

Browse files
committed
Added JSON Actor. Finished sample framework actors.
1 parent e1be5c8 commit 3f5d041

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

build.sbt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ libraryDependencies ++= Seq(
5353
//"com.typesafe.akka" %% "akka-testkit" % "2.5.18" % Test
5454
)
5555

56-
// Akka Actors
57-
libraryDependencies ++= Seq(
58-
"com.typesafe.akka" %% "akka-actor" % "2.5.18",
59-
//"com.typesafe.akka" %% "akka-testkit" % "2.5.18" % Test
60-
)
56+
// https://mvnrepository.com/artifact/com.google.code.gson/gson
57+
libraryDependencies += "com.google.code.gson" % "gson" % "2.8.5"
6158

6259

6360
// ---------------------------------------------------------------------------------------------------------------------
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
package org.codeoverflow.chatoverflow.connector.actor
22

33
import akka.actor.Actor
4+
import com.google.gson.{JsonObject, JsonParser}
45

6+
/**
7+
* The JSON Actor uses Google GSON to parse serialized json and enable traversing.
8+
*/
59
class JsonActor extends Actor {
6-
override def receive: Receive = ???
10+
val parser = new JsonParser
11+
12+
/**
13+
* Receives a ParseJSON Object to start parsing.
14+
*
15+
* @return the desired values, can be any type
16+
*/
17+
override def receive: Receive = {
18+
case ParseJSON(json, parse) =>
19+
val rootObject = parser.parse(json).getAsJsonObject
20+
parse(rootObject)
21+
}
722
}
23+
24+
/**
25+
* Send a ParseJSON-object to start parsing. The traversal is custom.
26+
*
27+
* @param json the serialized json string
28+
* @param parse a function what should happen with the parsed json. Return type is any
29+
*/
30+
case class ParseJSON(json: String, parse: JsonObject => Any)

0 commit comments

Comments
 (0)