从datastax驱动程序中的cassandra查询输出反序列化List <UserType>的列时出错

时间:2019-12-06 23:25:44

标签: cassandra datastax

反序列化方法:

override def deserialize(bytes: ByteBuffer, protocolVersion: ProtocolVersion): UserType = {

Option(bytes) match {
  case Some(value) if value.remaining == 0 =>
    throw new Exception(s"Cannot Deserialize empty bytes Array!!!! $this.getClass")
  case Some(value) =>
    val byteArray = new Array[Byte](bytes.remaining)
    bytes.duplicate.get(byteArray)
    objectMapper.readValue[java.util.List[UserType]] (byteArray, classOf[java.util.List[UserType]] ).get(0)
  case _ =>
    null
}

}

我能够通过自定义编解码器读取列的字节。但是,其反序列化失败并显示错误

  

java.io.CharConversionException:无效的UTF-32字符0x314c5555   (0x0010ffff以上)在char#3,字节#15)在   com.fasterxml.jackson.core.io.UTF32Reader.reportInvalid(UTF32Reader.java:195)     在   com.fasterxml.jackson.core.io.UTF32Reader.read(UTF32Reader.java:158)     在   com.fasterxml.jackson.core.json.ReaderBasedJsonParser._loadMore(ReaderBasedJsonParser.java:250)     在   com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:2354)     在   com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:672)     在   com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4340)     在   com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4189)     在   com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3266)

我如何反序列化接收到的字节?

cassandra中的类型定义为

CREATE TYPE canada_catalog.UserType (id text, flag1 BOOLEAN,flag2 BOOLEAN);

Cassandra列的类型为frozen<list<frozen<usertype>>>

0 个答案:

没有答案