开发者

How to generate several versions of Java classes generated by JAXB?

开发者 https://www.devze.com 2022-12-24 01:59 出处:网络
I recently generate two versions of Java classes generated by JAXB. So I get two packag开发者_如何学Pythones :

I recently generate two versions of Java classes generated by JAXB. So I get two packag开发者_如何学Pythones : V1_0 and V2_0

I notice that I have only one ObjectFactory generated. The problem is that this ObjectFactory is specific to a version (here it's specific to my version v1_0).

So the question is : Could I configure JAXB to allow to make one ObjectFactory for each version ?

Thanks a lot.


If the two versions of the API are in the same namespace, that's horrible! You'll have the object factory from one round of generation overwriting the object factory produced by the other (or inhibiting; I forget which xjc actually does). It's also horrible for clients of the API since they won't know what version of the API they're dealing with (unless you're doing other nasty tricks, which ought to be discouraged; if they're in the same namespace they should be the same API).

The fix is to put the two APIs in different namespaces so that they get generated into different packages with different object factories. (Also beware of any use of the -p option to xjc; that can cause things to go into the same namespace and give you these overwriting headaches.)


One object factory for both versions? Not, it is not possible. You get two sets of classes in two packages - it is not possible that one object factory serves both of them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号