I need help using JAXB to (de-)serialize a Polygon of the JTS Library:
When implementing the
class PolygonAdapter extends XmlAdapter[String,Polygon] {...}
and annotating the polygon field like:
@XmlRootElement(name = "Room")
case class Room(@XmlAttrib开发者_运维百科ute name: String, description: String,
@XmlJavaTypeAdapter(classOf[PolygonAdapter]) polygon: Polygon) {...}
I get the part classOf[PolygonAdapter])
marked reporting the following errors:
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>}
My Questions:
- How can I solve this problem?
- Is there a better way to (de-)serialize a complex object hierarchy in scala than using JAXB?
Thanks.
I am uncertain how to solve your first problem. Might be a problem with annotating a case class? Could try using a non-case class. But again very unsure about that. Might be related to this SO question?
scala: annotating accessor methods
However, have you looked at the Scala's built-in XML features?
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
edit: Could be worth to take a look at: http://scalaxb.org/ if you want to avoid using Scala's built in features...
精彩评论