Java/JAXB: Unmarshall Xml to specific subclass based on an attribute

后端 未结 5 2122

Is it possible to use JAXB to unmarshall xml to a specific Java class based on an attribute of the xml?


  

        
5条回答
  •  一个人的身影
    2020-11-27 19:28

    No, I'm afraid that's not an option, JAXB isn't that flexible.

    The best I can suggest is that you put a method on the Shape class which instantiates the "correct" type based on the attribute. The client code would invoke that factory method to obtain it.

    Best I can come up with, sorry.

提交回复
热议问题