I'm trying to return JSON when using the @RestController. I'm using Spring 4.1. Here's the exception I'm getting when calling listrestsites.html using a GET request. I have the fasterxml Jackson core and databind jars in my build path. Output of the accept from @requestheader = accept: application/json, text/javascript, /; q=0.01 Any help is appreciated. Thank you,
[DEBUG,ExceptionHandlerExceptionResolver] Resolving exception from handler [public java.util.List com.amci.spring3.controller.SitesRestController.listRestSites(java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation [DEBUG,DefaultListableBeanFactory] Returning cached instance of singleton bean 'exceptionControllerAdvice' [DEBUG,ExceptionHandlerExceptionResolver] Invoking @ExceptionHandler method: public org.springframework.web.servlet.ModelAndView
Here's my Restcontroller class:
@RestController
public class SitesRestController {
@Autowired
private AssetService assetService;
@RequestMapping("/listrestsites.html")
public List<Asset> listRestSites(@RequestHeader(value="accept") String accept) {
System.out.println(getLogLevel());
System.out.println("accept: " + accept);
return assetService.findAssets();
}
}
Also, snippet from my spring.xml:
<property name="defaultViews">
<list>
<!-- JSON View -->
<bean
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
</bean>
</list>
</property>
<property name="ignoreAcceptHeader" value="true" />
</bean>