[Exception handling] - Error: java.util.LinkedHashMap cannot be cast to ...;errorCode:5010000!

        The exception scene code is as follows:
            List<AssessmentDayVo> dayResultList = mobileService.queryDayWeight(LoginInfo.getDeptCode());
	    logger.info("[Daily volume] Collection before loop: {}",JSON.toJSON(dayResultList));     for(int i=0; i<dayResultList.size();i++){
 logger.info("[Daily volume] in loop: {}",JSON.toJSON(dayResultList.get(i))); 
		    	       
	    	AssessmentDayVo assessmentDayEntity=dayResultList.get(i);
			provinceInWeight += Double.parseDouble(assessmentDayEntity.getProvinceInWeight());
			throughWeight += Double.parseDouble(assessmentDayEntity.getThroughWeight());
			transitWeight += Double.parseDouble(assessmentDayEntity.getTransitWeight());
			transProvinceWeight += Double.parseDouble(assessmentDayEntity.getTransProvinceWeight());
			double hourWeight = Double.parseDouble(assessmentDayEntity.getProvinceInWeight()) + Double.parseDouble(assessmentDayEntity.getThroughWeight())
							  + Double.parseDouble(assessmentDayEntity.getTransitWeight()) + Double.parseDouble(assessmentDayEntity.getTransProvinceWeight());
			dayTotalWeight = dayTotalWeight + hourWeight;		
			hourMap.put(Integer.parseInt(assessmentDayEntity.getHour()), hourWeight);
		}

The part marked in red is the error report, and the error report is as follows:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.ymdd.galaxy.report.api.vo.mobile.AssessmentDayVo

The AssessmentDayVo entity class is as follows:

public class AssessmentDayVo implements Serializable{
	private static final long serialVersionUID = 1L;
	private String hour;
	private String provinceInWeight;
	private String transitWeight;
	private String throughWeight;
	private String transProvinceWeight;
        ...omitting get/set methods...

The log log is as follows:

【日货量】循环前集合:[{"hour":"00","provinceInWeight":"3.382","throughWeight":"2.494","transProvinceWeight":"9.159","transitWeight":"0.0"},{"hour":"01","provinceInWeight":"5.379","throughWeight":"0.324","transProvinceWeight":"10.516","transitWeight":"0.13"},{"hour":"02","provinceInWeight":"1.306","throughWeight":"0.165","transProvinceWeight":"2.751","transitWeight":"0.0"}……]

【日货量】循环中集合:{"hour":"00","provinceInWeight":"3.382","throughWeight":"2.494","transProvinceWeight":"9.159","transitWeight":"0.0"}

See if there is no problem, that is, the object turns to the object, and later repeated verification found:

The method of dayResultList.get(i) does not get an entity class, but a Map. The specific reason is unknown (please leave a message for advice).

With the reason, the method I thought of at the time was to convert the map into json, and then convert the json into the corresponding entity class, the method is as follows:

AssessmentDayVo assessmentDayEntity = JSON.parseObject(JSON.toJSONString(dayResultList.get(i)),AssessmentDayVo.class);

        Perfect solution! ! ! Xiaobai is here at the beginning, please advise me! ! !


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324823911&siteId=291194637