【问题标题】:Castor generate BigDecimal type for integer type in xsdCastor 为 xsd 中的整数类型生成 BigDecimal 类型
【发布时间】:2014-09-12 14:42:39
【问题描述】:

我使用 xsd 架构,例如:

<xsd:element name="TrxIdRs" type="TrxIdRs_Type"/>
<xsd:complexType name="TrxIdRs_Type">
    <xsd:simpleContent>
        <xsd:extension base="xsd:int">
            <xsd:attribute ref="trxStatusCode" use="required"/>
            <xsd:attribute ref="trxStatusDescr" use="required"/>
        </xsd:extension>
    </xsd:simpleContent>
</xsd:complexType>
<xsd:attribute name="trxStatusCode" type="xsd:int"/>
<xsd:attribute name="trxStatusDescr" type="xsd:string"/>

表示 XML 类似:

<TrxIdRs trxStatusCode="1" trxStatusDescr="descr">
    111000111
</TrxIdRs>

但 Castor 只为此架构生成 BigDecimal 类型:

public abstract class TrxIdRs_Type implements java.io.Serializable {
  //--------------------------/
 //- Class/Member Variables -/
//--------------------------/
/**
 * internal content storage
 */
private java.math.BigDecimal _content;
/**
 * Field _trxStatusCode.
 */
private java.lang.Integer _trxStatusCode;

是否有任何其他变体可以编写 xsd 或配置 castor 以在生成的 bean 中具有原始类型?

【问题讨论】:

  • 你能添加完整的xsd吗?... trxStatusCode和trxStatusDescr的声明在哪里?
  • 我无法显示完整的 xsd - 它太大了。添加了属性描述和元素声明
  • 我使用了 Jaxb,如果您更改 xsd 中的类型:decimal 工作正常;)
  • 我无法更改框架,其他 xml 元素会有太多更改。 (约22000)
  • 尝试使用 xsd:restriction 代替 xsd:extension。

标签: java xml xsd castor


【解决方案1】:

来自http://castor.codehaus.org/1.2/srcgen-example.html

Schema 十进制类型映射到 java.math.BigDecimal。

您应该使用外部绑定 .. link 有一个配置教程(第 7 页)。

【讨论】:

  • 什么意思?我不想有一个 Objects 类型,只有原始或至少 Integer,但不是 java.math.BigDecimal
  • DOC 描述了如何为 elements 设置用户定义的 java-type。只有可用的配置元素是:“。但是元素没有问题。复杂元素的内容(带有属性)有问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-20
  • 1970-01-01
相关资源
最近更新 更多