我正在尝试使用JsonDeserialize类,但IDE显示编译错误。
GateAnnotation.scala
package com.scryAnalytics.NLPAnnotationController.DAO
import com.scryAnalytics.NLPGeneric.DAO.FeatureMapDeserializer
import org.codehaus.jackson.annotate.JsonProperty
import org.codehaus.jackson.map.annotate.JsonDeserialize
import gate.{FeatureMap, Node}
import gate.annotation.AnnotationImpl
/**
* Created by sahil on 22/11/16.
*/
class GateAnnotation(id: Integer, start: Node, end: Node, types: String, features: FeatureMap) extends
AnnotationImpl(id, start, end, types, features) {
private final val serialVersionUID: Long = 1L
@JsonProperty
@JsonDeserialize(using = FeatureMapDeserializer.class)
}
FeatureMapDeserializer.scala
package com.scryAnalytics.NLPAnnotationController.DAO
import java.util.Map
import gate.{Factory, FeatureMap}
import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec._Object
import org.codehaus.jackson.JsonParser
import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
class FeatureMapDeserializer extends JsonDeserializer[FeatureMap] {
override def deserialize(jsonParser: JsonParser, deserializationContext: DeserializationContext): FeatureMap = {
val features = jsonParser.readValueAs(classOf[Map[_Object, _Object]])
val featureMap = Factory.newFeatureMap()
featureMap.putAll(features)
featureMap
}
}
错误(编译)是 @JsonDeserialize(using = FeatureMapDeserializer.class)。悬停在线上后的错误是 FeatureMapDeserializer类型的表达式不符合预期类型Class [< JsonDeserializer [_]]
我无法弄清楚原因,所以我期待任何建议。
提前致谢。
答案 0 :(得分:0)
您使用的是Java语法,而不是Scala语法。
@JsonProperty
@JsonDeserialize(using = classOf[FeatureMapDeserializer])
def foo = ???