HttpMediaTypeNotAcceptableException

I am having a problem with my jQuery function that I am trying to achieve is to populate the data in a list

Javascript function

function load() { $.getJSON('${findAdminGroupsURL}', { ajax : 'true' }, function(data) { var html = '<option value="">Groups</option>'; var len = data.length; for ( var i = 0; i < len; i++) { html += '<option value="' + data[i].name + '">' + data[i].name + '</option>'; } html += '</option>'; $('#selection').html(html); }); } 

Server side

 @RequestMapping(value = "groups", method = RequestMethod.GET) public @ResponseBody List<Group> getGroups() { return this.businessGroups(); } 

I call the load () function when loading, it runs the getGroups () function and returns the list successfully, but the problem is that getGroups () is complete

Function

(data) does not load, never falls into this function, but an error

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find an acceptable view

Can't I send a list of group objects or should it be a primitive Java type?

+6
source share
2 answers

I am not sure which version of spring you are using. I had the same problem and solved it by adding the bottom jackson to my classpath. My spring version is 3.2.2

 jackson-mapper-asl jackson-core-asl 

Here is my controller

 @RequestMapping(value="/{name}", method = RequestMethod.GET) public @ResponseBody List<Supplier> getSuppliers(@PathVariable String name) { searchDAO = (SearchDAO) SpringApplicationContext.getBean("searchDAO"); List<Supplier> suppliers = null; try { suppliers = searchDAO.searchSuppliersByZipCode(name); //assertTrue(suppliers.size()>=1); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return suppliers; } 

I only have the mvc annotation in my application context, there is no need for explicit content negotiation. When you have @ResponseBody , the default will be the json format, and json-json will be considered to convert your pojo.

0
source

Source: https://habr.com/ru/post/890758/


All Articles