Scala中的反序列化Case类无法正常运行sangria GraphQl

时间:2018-10-29 14:39:46

标签: scala deserialization graphql sangria

case class Location(value: String)

这是我希望Scala中的案例类同时存在于Request和Response对象中。 对于Request对象(也是一个案例类),我有:

implicit val loc = new FromInput[Location] {
    val marshaller = CoercedScalaResultMarshaller.default
    def fromResult(node: marshaller.Node) = {
      val ad = node.asInstanceOf[Map[String, Any]]
      Location(
        value = ad("value").asInstanceOf[String]
      )
    }
  }

实际的Request对象本身正在反序列化,例如:

implicit val manual = new FromInput[Request] {
    val marshaller = CoercedScalaResultMarshaller.default
    def fromResult(node: marshaller.Node) = {
      val ad = node.asInstanceOf[Map[String, Any]]
      Request(
        location = ad("location").asInstanceOf[Location],
        startTimeEpochMs = ad("startTimeEpochMs").asInstanceOf[Long],
        endTimeEpochMs = ad("endTimeEpochMs").asInstanceOf[Long]
      )
    }
  }

  implicit val LocationType = deriveObjectType[Unit, Location]()
  implicit val InputLocationType = deriveInputObjectType[Location]()
  implicit val RequestType = deriveInputObjectType[Request]()

代码可以编译,但是我有Runtime Exception: 无法初始化Schema.scala类并抛出NoClassDefinitionFound异常。

我是桑格利亚汽酒和graphQL的新手。如果您能在这里让我知道我的错误以及如何解决。这将是一个很大的帮助!非常感谢您的投入。

0 个答案:

没有答案