2

I am trying to convert List of objects into json with the help of jackson-mapper-asl libraries, but in response i got http 406 error. jackson-mapper-asl libraries are on my class path. Following is my Spring MVC controller code:

@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;
}

My Ajax request code:

$.ajax({
            url: url+"/"+parentId,
            type: 'GET',
            success: function(result) {
                var arr = $.parseJSON(result);
----------------------- 
Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126
  • 3
    you are using the wrong jackson dependencies check here http://stackoverflow.com/questions/26825276/spring-4-restcontroller-json-characteristics-not-acceptable-according-to-the-re – Master Slave Feb 23 '15 at 14:42
  • are you adding ?contentType : "application/json; charset=utf-8", dataType : "json", also what version of jackson using? support for Jackson has been focused on 2.0+ in spring 4 – Ali.Mojtahed Feb 23 '15 at 16:24

2 Answers2

12

With spring 4, we need to use following dependency:

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

The jackson-mapper-asl is used with spring 3.x. Thanks to @Master Slave for valid comment. Click here for more information: Spring 4 RestController JSON: characteristics not acceptable according to the request "accept" headers

Community
  • 1
  • 1
Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126
  • If I add the above dependency, my tomcat server 8 is getting stopped. What will be the issue? – Ajoe Jul 31 '17 at 13:59
0

I think you used in valid path variable param type ex:

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

instead of it, use the following method header it may work

 @ResponseBody public List<ProductCategory>   findSubCategories(@PathVariable Integer parentId)
Nalla Srinivas
  • 913
  • 1
  • 9
  • 17