我有以下案例类:
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对数据库进行读写。
Either
当前不受支持。我已经相应地更新了"支持的类型"wiki。
请注意,在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