2

我正在尝试解析一个类,出于某种原因,Jackson(实际上是 Scala 中的 Jerkson 接口)正在转储。我猜这可能与BoardOpen成为一个类的子MessageEvent类有关:

class BoardOpen(

  override val channel: String

) extends MessageEvent(channel)

class MessageEvent( val channel: String = "/" )

完整的错误:

The error com.codahale.jerkson.ParsingException: No suitable constructor found
for type [simple type, class engine.event.BoardOpen]: can not instantiate from J
SON object (need to add/enable type information?)
 at [Source: java.io.StringReader@4004c5b3; line: 1, column: 2]
        at com.codahale.jerkson.ParsingException$.apply(ParsingException.scala:17)
        at com.codahale.jerkson.Parser$class.parse(Parser.scala:86)
        at com.codahale.jerkson.Json$.parse(Json.scala:6)
        at com.codahale.jerkson.Parser$class.parse(Parser.scala:14)
        at com.codahale.jerkson.Json$.parse(Json.scala:6)
        at controllers.socket.MessageParser$.matchMsg(MessageParser.scala:59)
        at controllers.socket.MessageParser$.parseRawMessage(MessageParser.scala:90)
        at controllers.socket.MessageParser$.readStringMsg(MessageParser.scala:42)

这就是我去解析数据时发生的事情:

msgCase match {
       case "BoardOpen"            => parse[BoardOpen](msgData)

JSON看起来像:

{"channel":"/board"}

任何想法为什么它失败了?谢谢。

更新:

因为只有channel属性需要担心,所以我想我会看看如果我将解析更改为会发生什么parse[MessageEvent](msgData),奇怪的是它会吐出同样的错误:

The error com.codahale.jerkson.ParsingException: No suitable constructor found
for type [simple type, class com.alloyengine.powder.MessageEvent]: can not insta
ntiate from JSON object (need to add/enable type information?)
 at [Source: java.io.StringReader@34fd2520; line: 1, column: 2]
4

0 回答 0