`
woshixushigang
  • 浏览: 576114 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

org.codehaus.jackson.map.JsonMappingException: No serializer found for class ...

 
阅读更多

项目采用spring mvc 框架,spring封装的jdbc方式访问数据库,部分代码如下

@RequestMapping(value = "/xiangmu.html")
    public @ResponseBody
    ModelMap addWeiboComments(ModelMap modelMap, WeiboCommentsVO weiboCommentsVO) {
        //modelMap.clear();
        /* 权限验证 */
        if (this.user.get().getUid() <= 0) {
            return modelMap;
        }
        Map<String, String> map = getConditionParameters(this.request.get());
        MultiValueMap<String, String> multiValueMap = mapToMultiValueMap(map);
        ModelMap repositoryAdd = restTemplate.postForObject(RestAPIURLConstant.WEIBOCOMMENTS, multiValueMap, ModelMap.class);
        ModelMap repositoryGet = restTemplate.getForObject(RestAPIURLConstant.WEIBOCOMMENTS, ModelMap.class,
        repositoryAdd.get(WebApplicationConstant.FLAG_RESULT));

        modelMap.put(WebApplicationConstant.FLAG_STATUS, repositoryAdd.get(WebApplicationConstant.FLAG_STATUS));
        modelMap.put(WebApplicationConstant.FLAG_RESULT, repositoryGet.get(WebApplicationConstant.FLAG_RESULT));
        return modelMap;
    }

   js里面 获取相应属性,但是报错:

 

严重: Servlet.service() for servlet chenming threw exception
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.springframework.validation.DefaultMessageCodesResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: org.springframework.validation.support.BindingAwareModelMap["org.springframework.validation.BindingResult.weiboCommentsVO"]->org.springframework.validation.BeanPropertyBindingResult["messageCodesResolver"])
	at org.codehaus.jackson.map.ser.StdSerializerProvider$1.failForEmpty(StdSerializerProvider.java:89)
	at org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:62)
	at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
	at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
	at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)

 分析错误提示发现:jquery 获取异步返回的数据时候出现的问题,将modelmap.clear 去掉注释 后一切正常。

spring mvc 方式获取返回json数据时候,切记 方法里面加上 modelMap.clear();

但是要注意:jquery 获取返回数据时候,如果获取不到返回的属性 是不会报错的。所以问题还是出现在这个modelMap里面。

0
4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics