Skip to content

Commit 18b5631

Browse files
andrewtobilkopivovarit
authored andcommitted
HttpMediaTypeNotAcceptableException (eugenp#2145)
* code snippets for the `Java 9 Stream API improvements` article * code snippets for the `Java 9 Stream API improvements` article [2 attempt] * removed the first attempt * the Spring 5 WebClient * delted stream features test * HttpMediaTypeNotAcceptableExceptionExampleController [0] * reactive web client service was removed
1 parent ed7c169 commit 18b5631

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.exception;
2+
3+
import org.springframework.http.MediaType;
4+
import org.springframework.web.HttpMediaTypeNotAcceptableException;
5+
import org.springframework.web.bind.annotation.ExceptionHandler;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
import org.springframework.web.bind.annotation.ResponseBody;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import java.util.Collections;
11+
import java.util.Map;
12+
13+
@RestController
14+
public class HttpMediaTypeNotAcceptableExceptionExampleController {
15+
16+
@PostMapping(value = "/test", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
17+
public Map<String, String> test() {
18+
return Collections.singletonMap("key", "value");
19+
}
20+
21+
@ResponseBody
22+
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
23+
public String handleHttpMediaTypeNotAcceptableException() {
24+
return "acceptable MIME type:" + MediaType.APPLICATION_JSON_VALUE;
25+
}
26+
27+
}

0 commit comments

Comments
 (0)