我需要帮助使用JAXB来(取消)序列化JTS Library的多边形:
实施
时class PolygonAdapter extends XmlAdapter[String,Polygon] {...}
并注释多边形字段,如:
@XmlRootElement(name = "Room")
case class Room(@XmlAttribute name: String, description: String,
@XmlJavaTypeAdapter(classOf[PolygonAdapter]) polygon: Polygon) {...}
我标记的部分classOf[PolygonAdapter])
报告了以下错误:
Multiple markers at this line
- type mismatch; found : java.lang.Class[room.PolygonAdapter](classOf[room.PolygonAdapter]) required: java.lang.Class[_ <:
javax.xml.bind.annotation.adapters.XmlAdapter]
- annotation argument needs to be a constant; found: classOf[PolygonAdapter]
- annotation argument needs to be a constant; found: classOf{<null>}[PolygonAdapter]{<null>}
- type mismatch; found : java.lang.Class[room.PolygonAdapter](classOf[room.PolygonAdapter]) required: java.lang.Class[_ <:
javax.xml.bind.annotation.adapters.XmlAdapter]
- annotation argument needs to be a constant; found: classOf{<null>}[PolygonAdapter]{<null>}
感谢。
答案 0 :(得分:0)
我不确定如何解决你的第一个问题。注释案例类可能会有问题吗?可以尝试使用非案例类。但同样非常不确定。可能与这个问题有关吗?
scala: annotating accessor methods
但是,您是否看过Scala的内置XML功能?
http://www.ibm.com/developerworks/library/x-scalaxml/
http://www.scala-lang.org/node/131
http://www.codecommit.com/blog/scala/working-with-scalas-xml-support
编辑:如果你想避免使用Scala的内置功能,可能值得一看:http://scalaxb.org/ ...