咖啡伴侶

          呆在上海
          posts - 163, comments - 156, trackbacks - 0, articles - 2

          用XMLEncode輸出時候,有BigDecimal有時候不好使。

          Posted on 2008-03-28 10:07 oathleo 閱讀(548) 評論(0)  編輯  收藏 所屬分類: Java

          用XMLEncode輸出時候,如果有BigDecimal有時候不好使。
          原因是:如果類的變量在定義時候有初始值,而不是null,就必須要重載DefaultPersistenceDelegate的mutatesTo方法。
          關于這個說明,在網上這里可以看到:
          http://forum.java.sun.com/thread.jspa?threadID=631299&messageID=3642493

          有興趣的可以看看:
          //setup big decimal delegate.
          ????????? DefaultPersistenceDelegate bigDecimalDelegate = new DefaultPersistenceDelegate() {
          ????????????? protected Expression instantiate(Object oldInstance, Encoder out) {
          ????????????????? BigDecimal decimal = (BigDecimal) oldInstance;
          ????????????????? return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] {decimal.toString()});
          ????????????? }
          ????????????? //must override this method.
          ????????????? // see http://forum.java.sun.com/thread.jspa?threadID=631299&messageID=3642493
          ????????????? protected boolean mutatesTo(Object oldInstance, Object newInstance) {
          ????????????????? return oldInstance.equals(newInstance);
          ????????????? }
          ????????????? //--- Joshua
          ????????? };

          網上的牛人說:

          This works for BigDecimal properties that aren't initialized, i.e. null. But if you initialize the property, then this won't work unless you override mutatesTo in addition to instantiate mentioned above:

          protected boolean mutatesTo(Object oldInstance, Object newInstance) {
          return oldInstance.equals(newInstance);
          }

          主站蜘蛛池模板: 汝城县| 崇阳县| 建水县| 密云县| 淮阳县| 绥滨县| 长岛县| 无极县| 绥芬河市| 蓝田县| 平潭县| 临沧市| 阿拉尔市| 荆门市| 秦安县| 湟中县| 贡嘎县| 麻江县| 西盟| 阿鲁科尔沁旗| 德州市| 长垣县| 梨树县| 永年县| 沙雅县| 湄潭县| 登封市| 定州市| 云南省| 辉县市| 陵川县| 宁夏| 赤壁市| 桃园县| 贵州省| 图片| 永吉县| 峡江县| 建始县| 夹江县| 博客|