Is it possible to use JAXB to map from schema to a java.util.Map?

后端 未结 2 845
遥遥无期
遥遥无期 2020-12-09 09:57

I have an existing XML schema that contains a type that I would like to map to a Java Map of some sort using JAXB. My build process takes the schema and creates the beans. I

相关标签:
2条回答
  • 2020-12-09 10:37

    Your XJC file is using the "standard" javaType directive, which I believe is limited to converting String values to and from a representative java type. As such, it's only suitable for converting simple element and attribute content.

    The XJC tool provides an enhanced version of javaType, which in theory should be able to handle more complex structures. Unfortunately, this has yet to be implemented:

    https://java.net/jira/browse/JAXB-209 (unresolved)

    For instance, being able to map a schema type to a HashMap might be a likely requirement for those using model driven design/implementation. AFAICS, this is not possible today. Therefore, one must manually edit the generated code.

    Looks like you're out of luck.

    0 讨论(0)
  • 2020-12-09 10:51

    Have you looked at example here (Customized mapping of HashMap): http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html

    Need to create custom XmlAdapter I'm afraid.

    0 讨论(0)
提交回复
热议问题