salat是否支持在scala中进行类型化的序列化?

时间:2015-12-10 10:59:26

标签: mongodb scala salat

我有以下案例类:

case class DataEntity
(
  name: String,
  value: Either[Complex, String]
)
case class Complex (x: String, y: String)

据我所知,序列化(写入MongoDB)很顺利,但在反序列化时却失败了:

com.novus.salat.util.ToObjectGlitch: 

  argument type mismatch

  $anon$2(class catalog.DataEntity @ com.novus.salat.global.package$$anon$1@3fa48431) toObject failed on:
  SYM: catalog.DataEntity
  CONSTRUCTOR
public catalog.DataEntity(java.lang.String,scala.util.Either<catalog.Complex, java.lang.String>)

---------- CONSTRUCTOR EXPECTS FOR PARAM [0] --------------
NAME:         name
TYPE:         java.lang.String
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore       false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: java.lang.String
VALUE:
TESTTEXT
------------------------------------------------------------


---------- CONSTRUCTOR EXPECTS FOR PARAM [1] --------------
NAME:         value
TYPE:         scala.util.Either<catalog.Complex, java.lang.String>
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore       false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: com.mongodb.BasicDBList
VALUE:
[ [ "File" , "/bin/ls" ...
------------------------------------------------------------

上面的输出手动匹配上面的简化案例类。 我正在使用salatDAO读取和写入数据库。

1 个答案:

答案 0 :(得分:0)

目前不支持

Either。我已相应更新了“支持的类型”维基。

请注意,在Salat 1.10.0-SNAPSHOT中,您将收到如下错误(尝试从JSON字符串反序列化时):

scala> SalatExamples.eitherHolder()
serialized EitherHolder(Left(data)) to { "_typeHint" : "com.novus.salat.examples.EitherHolder" , "either" : [ "data"]} for storage in mongo

com.novus.salat.json.UnsupportedJsonTransformationException: serialize: Unsupported JSON transformation for class='scala.util.Left', value='Left(data)'

NOTE: salat has certain limitations. It cannot deserialize JSON into case classes having fields such as:
- Arrays such as Array[String]
- Nested collections such as Map[String, List[String]]
- Optional collections such as Option[List[String]]

For more information, please visit: https://github.com/salat/salat/wiki/SupportedTypes

https://github.com/salat/salat/wiki/SupportedTypes

另请参阅:https://github.com/noahlz/salat-examples/blob/master/src/main/scala/com/novus/salat/examples/SalatExamples.scala