JAXBContext, jaxb.properties and moxy

不羁岁月 提交于 2019-12-01 04:55:12

问题


The jaxb.properties needs to be in the same package as the domain classes you are creating the JAXBContext on.

I am using Moxy's xml driven configuration since I doesn't want to use annotations or XJC generated objects. I have an existing domain classes that are spread across multiple packages. Does this mean that i need to have the jaxb.properties present in all those packages or there is a better alternative (Maybe writing my own implementation of some interface that can read from a jvm arg or something)?


回答1:


Does this mean that i need to have the jaxb.properties present in all those packages?

If you are creating your JAXBContext on classes, then you need to have a jaxb.properties file in at least one of the packages of the domain classes passed in. In the example below you could have a jaxb.properties file in either package1 or package2.

JAXBContext jc = JAXBContext.newInstance(package1.Foo.class, package2.Bar.class);

If you are creating your JAXBContext on package names, then you need to have a jaxb.properties files in at least one of the packages. Note that packages are separated by a ':'.

JAXBContext jc = JAXBContext.newInstance("package1:package2");

or there is a better alternative

My preference is to use the standard JAXB APIs with a jaxb.properties file to specify MOXy as the JAXB provider. Some people prefer using the native MOXy APIs to do this:

JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {Foo.class, Bar.class}, null);

For More Information

  • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html


来源:https://stackoverflow.com/questions/11785543/jaxbcontext-jaxb-properties-and-moxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!