[英]Does salat support de/serialization of type Either in scala?
I have the following case classes: 我有以下案例类:
case class DataEntity
(
name: String,
value: Either[Complex, String]
)
case class Complex (x: String, y: String)
As far as I can see, serialization (writing to MongoDB) goes fine, but it fails in deserializing: 据我所知,序列化(写入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" ...
------------------------------------------------------------
The output above is manually matched to the simplified case classes above. 上面的输出手动匹配上面的简化案例类。 I am using salatDAO for reading and writing to DB.
我正在使用salatDAO来读写DB。
Either
is not currently supported. 目前不支持
Either
一种。 I've updated the "Supported Types" wiki accordingly. 我已相应更新了“支持的类型”维基。
Note that in Salat 1.10.0-SNAPSHOT, you will get an error like the following (when attempting to deserialize from JSON strings): 请注意,在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/salat/salat/wiki/SupportedTypes
See also: https://github.com/noahlz/salat-examples/blob/master/src/main/scala/com/novus/salat/examples/SalatExamples.scala 另见: https : //github.com/noahlz/salat-examples/blob/master/src/main/scala/com/novus/salat/examples/SalatExamples.scala
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.