Marshalling/unmarshalling test.
This commit is contained in:
2
.idea/modules/root-build.iml
generated
2
.idea/modules/root-build.iml
generated
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module external.linked.project.id="root-build" external.linked.project.path="$MODULE_DIR$/../../project" external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" sbt.imports="SUB:DOLLAR666c86f869e8681275c2.`root`, _root_.sbt.Keys._, _root_.sbt._, _root_.sbt.plugins.IvyPlugin, _root_.sbt.plugins.JvmPlugin, _root_.sbt.plugins.CorePlugin, _root_.sbt.plugins.JUnitXmlReportPlugin, _root_.sbt.plugins.Giter8TemplatePlugin, _root_.scala.xml.{TopScope=>SUB:DOLLARscope}" sbt.resolvers="https://repo1.maven.org/maven2/|maven|public, file:/home/nnm/.sbt/preloaded/|maven|local-preloaded, /home/nnm/.ivy2/cache|ivy|Local cache" type="SBT_MODULE" version="4">
|
<module external.linked.project.id="root-build" external.linked.project.path="$MODULE_DIR$/../../project" external.root.project.path="$MODULE_DIR$/../.." external.system.id="SBT" sbt.imports="SUB:DOLLAR484980a9ef0855c97e1c.`root`, _root_.sbt.Keys._, _root_.sbt._, _root_.sbt.plugins.IvyPlugin, _root_.sbt.plugins.JvmPlugin, _root_.sbt.plugins.CorePlugin, _root_.sbt.plugins.JUnitXmlReportPlugin, _root_.sbt.plugins.Giter8TemplatePlugin, _root_.scala.xml.{TopScope=>SUB:DOLLARscope}" sbt.resolvers="https://repo1.maven.org/maven2/|maven|public, file:/Users/pavelkachalouski/.sbt/preloaded/|maven|local-preloaded, /Users/pavelkachalouski/.ivy2/cache|ivy|Local cache" type="SBT_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<output url="file://$MODULE_DIR$/../../project/target/idea-classes" />
|
<output url="file://$MODULE_DIR$/../../project/target/idea-classes" />
|
||||||
<output-test url="file://$MODULE_DIR$/../../project/target/idea-test-classes" />
|
<output-test url="file://$MODULE_DIR$/../../project/target/idea-test-classes" />
|
||||||
|
|||||||
82
.idea/modules/root.iml
generated
82
.idea/modules/root.iml
generated
@@ -15,45 +15,8 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="sbt: com.google.code.gson:gson:2.8.1:jar" level="project" />
|
<orderEntry type="library" name="sbt: com.google.code.gson:gson:2.8.1:jar" level="project" />
|
||||||
<orderEntry type="library" name="sbt: com.typesafe:config:1.3.2:jar" level="project" />
|
<orderEntry type="library" name="sbt: io.spray:spray-json_2.12:1.3.4:jar" level="project" />
|
||||||
<orderEntry type="library" name="sbt: com.typesafe:ssl-config-core_2.12:0.2.3:jar" level="project" />
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-http-spray-json_2.12:10.1.1:jar" level="project" />
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-actor_2.12:2.5.12:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-http-core_2.12:10.1.1:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-http_2.12:10.1.1:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-parsing_2.12:10.1.1:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-protobuf_2.12:2.5.12:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-stream_2.12:2.5.12:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.netty:netty-reactive-streams:1.0.8:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: com.vk.api:sdk:0.5.12:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: commons-codec:commons-codec:1.9:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: commons-io:commons-io:2.5:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: commons-logging:commons-logging:1.2:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-buffer:4.0.48.Final:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-codec:4.0.48.Final:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-codec-http:4.0.48.Final:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-common:4.0.48.Final:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-handler:4.0.48.Final:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-transport:4.0.48.Final:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: io.netty:netty-transport-native-epoll:4.0.48.Final:linux-x86_64:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.apache.commons:commons-collections4:4.1:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.apache.commons:commons-lang3:3.6:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.apache.httpcomponents:httpclient:4.5.3:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.apache.httpcomponents:httpcore:4.4.6:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.apache.httpcomponents:httpmime:4.5.3:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.asynchttpclient:async-http-client:2.0.33:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.asynchttpclient:async-http-client-netty-utils:2.0.33:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.asynchttpclient:netty-codec-dns:2.0.33:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.asynchttpclient:netty-resolver:2.0.33:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.asynchttpclient:netty-resolver-dns:2.0.33:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.reactivestreams:reactive-streams:1.0.2:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.scala-lang:scala-library:2.12.6:jar" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="sbt: org.scala-lang:scala-reflect:2.12.6:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.scala-lang.modules:scala-java8-compat_2.12:0.8.0:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.scala-lang.modules:scala-parser-combinators_2.12:1.1.0:jar" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="sbt: org.scala-lang.modules:scala-xml_2.12:1.0.6:jar" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="sbt: org.scalactic:scalactic_2.12:3.0.5:jar" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="sbt: org.scalatest:scalatest_2.12:3.0.5:jar" level="project" />
|
|
||||||
<orderEntry type="library" name="sbt: org.slf4j:slf4j-api:1.7.25:jar" level="project" />
|
|
||||||
<orderEntry type="module-library">
|
<orderEntry type="module-library">
|
||||||
<library name="sbt: unmanaged-sources-and-docs">
|
<library name="sbt: unmanaged-sources-and-docs">
|
||||||
<CLASSES />
|
<CLASSES />
|
||||||
@@ -63,7 +26,44 @@
|
|||||||
</SOURCES>
|
</SOURCES>
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</orderEntry>
|
||||||
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-http-spray-json_2.12:10.1.1:jar" level="project" />
|
<orderEntry type="library" name="sbt: org.slf4j:slf4j-api:1.7.25:jar" level="project" />
|
||||||
<orderEntry type="library" name="sbt: io.spray:spray-json_2.12:1.3.4:jar" level="project" />
|
<orderEntry type="library" scope="TEST" name="sbt: org.scalatest:scalatest_2.12:3.0.5:jar" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="sbt: org.scalactic:scalactic_2.12:3.0.5:jar" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="sbt: org.scala-lang.modules:scala-xml_2.12:1.0.6:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.scala-lang.modules:scala-parser-combinators_2.12:1.1.0:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.scala-lang.modules:scala-java8-compat_2.12:0.8.0:jar" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="sbt: org.scala-lang:scala-reflect:2.12.6:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.scala-lang:scala-library:2.12.6:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.reactivestreams:reactive-streams:1.0.2:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.asynchttpclient:netty-resolver-dns:2.0.33:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.asynchttpclient:netty-resolver:2.0.33:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.asynchttpclient:netty-codec-dns:2.0.33:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.asynchttpclient:async-http-client-netty-utils:2.0.33:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.asynchttpclient:async-http-client:2.0.33:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.apache.httpcomponents:httpmime:4.5.3:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.apache.httpcomponents:httpcore:4.4.6:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.apache.httpcomponents:httpclient:4.5.3:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.apache.commons:commons-lang3:3.6:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: org.apache.commons:commons-collections4:4.1:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-transport-native-epoll:4.0.48.Final:linux-x86_64:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-transport:4.0.48.Final:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-handler:4.0.48.Final:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-common:4.0.48.Final:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-codec-http:4.0.48.Final:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-codec:4.0.48.Final:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: io.netty:netty-buffer:4.0.48.Final:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: commons-logging:commons-logging:1.2:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: commons-io:commons-io:2.5:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: commons-codec:commons-codec:1.9:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.vk.api:sdk:0.5.12:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.netty:netty-reactive-streams:1.0.8:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-stream_2.12:2.5.12:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-protobuf_2.12:2.5.12:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-parsing_2.12:10.1.1:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-http_2.12:10.1.1:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-http-core_2.12:10.1.1:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe.akka:akka-actor_2.12:2.5.12:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe:ssl-config-core_2.12:0.2.3:jar" level="project" />
|
||||||
|
<orderEntry type="library" name="sbt: com.typesafe:config:1.3.2:jar" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -10,8 +10,18 @@ object TelegramEntities extends SprayJsonSupport with DefaultJsonProtocol {
|
|||||||
error_code: Option[Int] = None,
|
error_code: Option[Int] = None,
|
||||||
result: T)
|
result: T)
|
||||||
|
|
||||||
|
object Response {
|
||||||
|
implicit val responseGetMeFormat: RootJsonFormat[Response[GetMe]] = jsonFormat4(Response[GetMe])
|
||||||
|
implicit val responseWebhookInfoFormat: RootJsonFormat[Response[WebhookInfo]] = jsonFormat4(Response[WebhookInfo])
|
||||||
|
implicit val responseStringFormat: RootJsonFormat[Response[String]] = jsonFormat4(Response[String])
|
||||||
|
}
|
||||||
|
|
||||||
case class GetMe(id: Int, is_bot: Boolean, first_name: String, username: String)
|
case class GetMe(id: Int, is_bot: Boolean, first_name: String, username: String)
|
||||||
|
|
||||||
|
object GetMe {
|
||||||
|
implicit val getMeFormat: RootJsonFormat[GetMe] = jsonFormat4(GetMe.apply)
|
||||||
|
}
|
||||||
|
|
||||||
case class InlineQuery(id: String,
|
case class InlineQuery(id: String,
|
||||||
from: User,
|
from: User,
|
||||||
location: Location,
|
location: Location,
|
||||||
@@ -98,11 +108,19 @@ object TelegramEntities extends SprayJsonSupport with DefaultJsonProtocol {
|
|||||||
|
|
||||||
case class InputFile()
|
case class InputFile()
|
||||||
|
|
||||||
|
object InputFile {
|
||||||
|
implicit val inputFileFormat: RootJsonFormat[InputFile] = jsonFormat0(InputFile.apply)
|
||||||
|
}
|
||||||
|
|
||||||
case class Webhook(url: String,
|
case class Webhook(url: String,
|
||||||
certificate: Option[InputFile] = None,
|
certificate: Option[InputFile] = None,
|
||||||
max_connections: Option[Int] = None,
|
max_connections: Option[Int] = None,
|
||||||
allowed_updates: Option[Seq[String]] = None)
|
allowed_updates: Option[Seq[String]] = None)
|
||||||
|
|
||||||
|
object Webhook {
|
||||||
|
implicit val webHookFormat: RootJsonFormat[Webhook] = jsonFormat4(Webhook.apply)
|
||||||
|
}
|
||||||
|
|
||||||
case class WebhookInfo(url: String,
|
case class WebhookInfo(url: String,
|
||||||
has_custom_certificate: Boolean,
|
has_custom_certificate: Boolean,
|
||||||
pending_update_count: Int,
|
pending_update_count: Int,
|
||||||
@@ -111,12 +129,7 @@ object TelegramEntities extends SprayJsonSupport with DefaultJsonProtocol {
|
|||||||
max_connections: Option[Int] = None,
|
max_connections: Option[Int] = None,
|
||||||
allowed_updates: Option[Seq[String]] = None)
|
allowed_updates: Option[Seq[String]] = None)
|
||||||
|
|
||||||
implicit val inputFileFormat: RootJsonFormat[InputFile] = jsonFormat0(InputFile)
|
object WebhookInfo {
|
||||||
implicit val webHookFormat: RootJsonFormat[Webhook] = jsonFormat4(Webhook)
|
implicit val webHookInfoFormat: RootJsonFormat[WebhookInfo] = jsonFormat7(WebhookInfo.apply)
|
||||||
implicit val webHookInfoFormat: RootJsonFormat[WebhookInfo] = jsonFormat7(WebhookInfo)
|
}
|
||||||
implicit val getMeFormat: RootJsonFormat[GetMe] = jsonFormat4(GetMe)
|
|
||||||
// responses
|
|
||||||
implicit val responseGetMeFormat: RootJsonFormat[Response[GetMe]] = jsonFormat4(Response[GetMe])
|
|
||||||
implicit val responseWebhookInfoFormat: RootJsonFormat[Response[WebhookInfo]] = jsonFormat4(Response[WebhookInfo])
|
|
||||||
implicit val responseStringFormat: RootJsonFormat[Response[String]] = jsonFormat4(Response[String])
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/test/scala/example/MarshalSpec.scala
Normal file
33
src/test/scala/example/MarshalSpec.scala
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
|
||||||
|
import akka.http.scaladsl.unmarshalling.Unmarshal
|
||||||
|
import akka.stream.Materializer
|
||||||
|
import akka.util.ByteString
|
||||||
|
import org.scalatest.FlatSpec
|
||||||
|
|
||||||
|
import scala.concurrent.Await
|
||||||
|
import scala.concurrent.ExecutionContext.Implicits.global
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
import spray.json._
|
||||||
|
|
||||||
|
case class Text(t: Option[String], t1: Option[String])
|
||||||
|
|
||||||
|
trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
|
||||||
|
implicit val textFormat = jsonFormat2(Text)
|
||||||
|
}
|
||||||
|
|
||||||
|
class MarshalSpec extends FlatSpec with JsonSupport {
|
||||||
|
|
||||||
|
"Marshal to MessageEntity" should "work" in {
|
||||||
|
implicit val mat: Materializer = null
|
||||||
|
val body =
|
||||||
|
"""
|
||||||
|
|{"t1": "some text value"}
|
||||||
|
""".stripMargin
|
||||||
|
// val bytes = ByteString(body)
|
||||||
|
val f = Unmarshal(body).to[Text]
|
||||||
|
val entity = Await.result(f, 1 second)
|
||||||
|
println(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user