久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 fractionDigits 對 BigDecimal 進(jìn)行 JAXB 編組

JAXB marshalling for BigDecimal using fractionDigits(使用 fractionDigits 對 BigDecimal 進(jìn)行 JAXB 編組)
本文介紹了使用 fractionDigits 對 BigDecimal 進(jìn)行 JAXB 編組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

所以這是我的問題.我得到了一個 XSD,我生成的 XML 文件應(yīng)該遵守該 XSD.使用 org.apache.cxf.cxf-xjc-plugin maven 插件和外部綁定文件生成源代碼.但是當(dāng)我嘗試編組我的對象時,生成的 XML 不符合我的要求.

So here's my problem. I'm given an XSD to which my generated XML file should comply. Using the org.apache.cxf.cxf-xjc-plugin maven plugin and an external binding file I generate the source code. But when I'm trying marshall my object the generated XML doesn't meet my requirements.

我的 XSD 包含以下內(nèi)容:

My XSD contains the following:

<xsd:element maxOccurs="1" minOccurs="0" name="amount">
  <xsd:simpleType>
    <xsd:restriction base="xsd:decimal">
      <xsd:totalDigits value="13" />
      <xsd:fractionDigits value="2" />
    </xsd:restriction>
  </xsd:simpleType>
</xsd:element>
...
<xsd:element maxOccurs="1" minOccurs="0" name="rate">
  <xsd:simpleType>
    <xsd:restriction base="xsd:decimal">
      <xsd:totalDigits value="8" />
      <xsd:fractionDigits value="5" />
    </xsd:restriction>
  </xsd:simpleType>
</xsd:element>

生成的 XML 片段如下所示:

And the generated piece of XML looks like this:

<amount>109.5</amount>
...
<rate>10.25</rate>

雖然我期待它是:

<amount>109.50</amount>
...
<rate>10.25000</rate>

有沒有辦法以干凈的方式解決這個問題?

Is there a way to solve this problem in a clean way?

我不希望為每個 totalDigitsfractionDigits 組合編寫多個適配器.由于 XSD 可能會發(fā)生變化,我想保持生成的源代碼不變.

I would prefer not writing several adapters for every single totalDigits, fractionDigits combination. And as the XSD is subject to change I'd like to leave the generated source code untouched.

推薦答案

對于這個用例,您需要使用 XmlAdapter.下面是一個示例綁定文件,可幫助您生成它們.邏輯將包含在 DecimalFormatter 類中,該類包含所有不同所需格式的方法.

You will need to use XmlAdapter for this use case. Below is a sample binding file that will help you generate them. The logic would be contained in a DecimalFormatter class that contained methods for all the different required formats.

<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
    <jxb:bindings schemaLocation="schema.xsd">
        <jxb:bindings node="http://xs:element[@name='amount']">
            <jxb:property>
                <jxb:baseType>
                    <jxb:javaType name="java.math.BigDecimal"
                        parseMethod="org.example.DecimalFormatter.parseDecimal"
                        printMethod="org.example.DecimalFormatter.printDecimal_2Places" />
                </jxb:baseType>
            </jxb:property>
        </jxb:bindings>
        <jxb:bindings node="http://xs:element[@name='rate']">
            <jxb:property>
                <jxb:baseType>
                    <jxb:javaType name="java.math.BigDecimal"
                        parseMethod="org.example.DecimalFormatter.parseDecimal"
                        printMethod="org.example.DecimalFormatter.printDecimal_5Places" />
                </jxb:baseType>
            </jxb:property>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

更多信息

  • http://blog.bdoughan.com/2011/08/xml-schema-to-java-generating.html

這篇關(guān)于使用 fractionDigits 對 BigDecimal 進(jìn)行 JAXB 編組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩av在线免费 | 国产欧美精品一区二区色综合 | 国产乱人伦 | 不卡一区二区三区四区 | 最新国产视频 | 精久久久久 | 国产黄色大片在线观看 | 91精品中文字幕一区二区三区 | www.中文字幕.com| 伊人伊人 | 亚洲 一区| 久久国产欧美日韩精品 | 国产精品久久久久久久久久久久午夜片 | 一区二区三区四区在线 | 日本91av视频 | 91中文字幕 | 成人精品一区二区三区 | 日本黄色免费大片 | 一级毛片在线看 | 成人免费影院 | 成人在线视频免费播放 | 国产免费自拍 | 本道综合精品 | 天天操网 | 久久99精品国产 | 亚洲成人一区 | 成人国产在线观看 | 国产精品欧美一区二区三区不卡 | 久久综合色综合 | 91精品国产色综合久久 | 天堂在线1 | 成人毛片视频免费 | 成人免费在线视频 | 国产农村一级国产农村 | 久久久久国产 | 国产一区二区在线视频 | 亚洲国产精品久久久久久 | 国产精品自产拍在线观看蜜 | 久久国产精品免费一区二区三区 | 亚洲v日韩v综合v精品v | 国产视频一区二区 |