gpt4 book ai didi

xml - JAXB 绑定(bind) - 将 typesafeEnumBase 设置为空(将枚举转换为字符串)

转载 作者:数据小太阳 更新时间:2023-10-29 02:55:50 37 4
gpt4 key购买 nike

根据link

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 设置了以下内容:

<jxb:globalBindings typesafeEnumBase=""/>

并且在运行 jaxb2-maven-plugin 时出现以下异常:

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

我只想将以下内容转换为 String 而不是 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 没有一个答案对我有用(都试过了).

最佳答案

设置如下

<jxb:globalBindings typesafeEnumMaxMembers="0"/>

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

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.

关于xml - JAXB 绑定(bind) - 将 typesafeEnumBase 设置为空(将枚举转换为字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46927872/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com