JAXB绑定 - 将typesafeEnumBase设置为空(将枚举转换为字符串) [英] JAXB bindings - set typesafeEnumBase to empty (convert enumerations to strings)

查看:455
本文介绍了JAXB绑定 - 将typesafeEnumBase设置为空(将枚举转换为字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据链接


如果typesafeEnumBase设置为xsd:string,那么它将是
的全局方式,指定所有简单类型定义直接派生或$ b间接来自xsd:string并且具有枚举方面的$ b应该是
默认绑定到类型安全枚举。如果typesafeEnumBase设置为
空字符串,,默认情况下,任何简单的类型定义都不会绑定到
类型安全枚举类。 typesafeEnumBase的值可以是
任何原子简单类型定义除了xsd:boolean 和两个二进制
类型。

If typesafeEnumBase is set to xsd:string, it would be a global way to specify that all simple type definitions deriving directly or indirectly from xsd:string and having enumeration facets should be bound by default to a typesafe enum. If typesafeEnumBase is set to an empty string, "", no simple type definitions would ever be bound to a typesafe enum class by default. The value of typesafeEnumBase can be any atomic simple type definition except xsd:boolean and both binary types.

所以我设置了我的 binding.xjb 以下内容:

So I have set to my binding.xjb the following:

<jxb:globalBindings typesafeEnumBase=""/>

以及运行 jaxb2-maven-plugin时我得到以下异常:

and when running the jaxb2-maven-plugin I get the following exception:

lineNumber: 5; columnNumber: 46; cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_typesafeEnumBaseglobalBindings'.
...
lineNumber: 5; columnNumber: 46; cvc-attribute.3: The value '' of attribute 'typesafeEnumBase' on element 'jxb:globalBindings' is not valid with respect to its type, 'null'.

据我所知,我无法设置空字符串 typesafeEnumBase 即使文档说明了这一点。文档还提到它不能是 xsd:boolean

As far as I understand I cannot set the empty string "" to typesafeEnumBase even though the documentation says so. Documentation also mentions that it cannot be xsd:boolean.

我想要的只是将以下内容转换为 String 而不是 enum

All I want is to convert the following to String instead of enum

<xs:simpleType name="phraseID">
    <xs:restriction base="escapedStringUserType">
        <xs:enumeration value="NOT_SPECIFIED"/>
        <xs:enumeration value="X000-9999"/>
        <xs:enumeration value="X000-9998"/>
    </xs:restriction>
</xs:simpleType>

相关的SO问题是 here 但由于我无法设置空字符串或设置 xsd:boolean 的值为 typesafeEnumBase 这些答案都不适合我(两者都试过)。

A relevant SO question is here but since I cannot set the empty string "" or set the xsd:boolean value to typesafeEnumBase none of the answers work for me (tried both).

推荐答案

设置以下内容

<jxb:globalBindings typesafeEnumMaxMembers="0"/>

不会为具有枚举限制的所有简单类型生成任何枚举,而是将它们转换为字符串,但是在控制台中吐出警告,如下所示:

will not generate any enums for all simple types with enumeration restrictions instead will convert them to strings, however it spits out warnings in the console like the following:

Simple type "xxx-address" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 10, current limit: 0. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.

这篇关于JAXB绑定 - 将typesafeEnumBase设置为空(将枚举转换为字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆