Java Enum with XML Beans?

When using Apache XML Beans to generate types from xsd: enumeration types, XMLBeans generates custom classes that are not Java 5 enums, but some kind of special class to represent the enumeration.

This may be because XMLBeans is older than Java 5 and there were no enumerations at that time, or you still want to maintain compatibility with Java 1.4. However, I would like to get the “real” enumeration types, so my question is: is there a way to generate Java 5 enumerations with Apache XML Beans?

( Jaxb does this as I want, but I'm not sure if I want to remove XMLBeans and introduce Jaxb just for that in detail.)

+3
source share
1 answer

I don’t think you can achieve what you want with XML beans. You even mentioned the reason yourself. I would recommend you move to JaxB.

But if you really want to use XML beans, I would suggest you a patch. You can post-process generated classes and convert them to enumerations. In the past, I have done something similar using ant tasks. There are ant tasks that know how to perform line replacements, so this is not a problem. In the worst case, you can implement your own task in java. But I believe that you do not have it. I think this is the easiest solution.

Good luck.

+1
source

Source: https://habr.com/ru/post/1791153/


All Articles