zoukankan      html  css  js  c++  java
  • xstream.fromXML 忽略没有的节点

    xml中存在节点,而model中不存在,就会报错:

    com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field com.creditharmony.adapter.model.crif.CrifBodyAppVar.App_amt

    -------------解决方案----------

    重写XStream中的方法:

    package com.creditharmony.adapter.core.service;
    
    import com.thoughtworks.xstream.XStream;
    import com.thoughtworks.xstream.io.xml.DomDriver;
    import com.thoughtworks.xstream.mapper.MapperWrapper;
    
    public class XStreamEx extends XStream {
    	 public XStreamEx(DomDriver domDriver) {
    		 super();
    	}
    
    	@Override
    	  protected MapperWrapper wrapMapper(MapperWrapper next) {
    	    return new MapperWrapper(next) {
    	      @Override
    	      public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") Class definedIn,
    	              String fieldName) {
    	        if (definedIn == Object.class) {
    	          return false;
    	        }
    	        return super.shouldSerializeMember(definedIn, fieldName);
    	      }
    	    };
    	  }
    
    }
    

     使用:

    直接new对象即可.

    XStreamEx xstream = new XStreamEx(new DomDriver(Constant.DEFAULT_CHARSET)); 
    
  • 相关阅读:
    容斥原理
    泰勒展开
    初等微积分
    粒子群优化(微粒群算法)
    生成函数
    FFT例题
    图论例题
    线段求交
    期望小小结
    [Violet]天使玩偶/SJY摆棋子
  • 原文地址:https://www.cnblogs.com/hoge/p/7444366.html
Copyright © 2011-2022 走看看