2

我正在尝试借助jackson-mapper-asl库将对象列表转换为 json,但作为响应,我收到了 http406错误。jackson-mapper-asl图书馆在我的班级路径上。以下是我的 Spring MVC 控制器代码:

@RequestMapping(value="/find-sub-categories/{parentId}", method=RequestMethod.GET)
@ResponseBody public List<ProductCategory> findSubCategories(@PathVariable(value="parentId") ProductCategory productCategory) {
    logger.info("In ADMIN findSubCategories Contoller AJAX GET");

    List<ProductCategory> categories = productCategoryService.findAllChildProductCategoriesByParent(productCategory);
    return categories;
}

我的 Ajax 请求代码:

$.ajax({
            url: url+"/"+parentId,
            type: 'GET',
            success: function(result) {
                var arr = $.parseJSON(result);
----------------------- 
4

2 回答 2

12

有了spring 4,我们需要使用以下依赖项:

<dependency>
 <groupId>com.fasterxml.jackson.core</groupId>
 <artifactId>jackson-databind</artifactId>
 <version>2.5.1</version>
</dependency>

jackson-mapper-asl一起使用spring 3.x。感谢@Master Slave 的有效评论。单击此处了解更多信息: Spring 4 RestController JSON:根据请求“接受”标头不可接受的特征

于 2015-02-24T04:27:27.173 回答
0

我认为您在有效的路径变量参数类型中使用了 ex:

@RequestMapping(value="/find-sub-categories/{parentId}", method=RequestMethod.GET)
@ResponseBody public List<ProductCategory>   findSubCategories@PathVariable(value="parentId") ProductCategory productCategory)

代替它,使用以下方法标头它可能会起作用

 @ResponseBody public List<ProductCategory>   findSubCategories(@PathVariable Integer parentId)
于 2015-02-24T04:39:17.363 回答