Restful web service 415
@RestController
@RequestMapping(value="/uri",produces = "application/json",
consumes="application/json")
public class VisitorService {
VisitorDAO vis=new VisitorDAO();
@RequestMapping(value = "/ex" ,method = RequestMethod.POST)
public String showDetails(@RequestBody VisitorDTO visitor){
vis.addVisitorEntry(visitor);
return "success"+visitor;
}}
Above is my rest service.
whenever I hit a post using the URL with the below JSON,
{
"phoneNumber" : 188892,
"name" : "kikiki" ,
"email" : "loa@gmail.com",
"purpose" : "Business",
"hostName" : "sjs S Murthy"
}
im getting HTTP Status 415 – Unsupported Media Type.
why would that be?
java json spring rest http-status-code-415
New contributor
add a comment |
@RestController
@RequestMapping(value="/uri",produces = "application/json",
consumes="application/json")
public class VisitorService {
VisitorDAO vis=new VisitorDAO();
@RequestMapping(value = "/ex" ,method = RequestMethod.POST)
public String showDetails(@RequestBody VisitorDTO visitor){
vis.addVisitorEntry(visitor);
return "success"+visitor;
}}
Above is my rest service.
whenever I hit a post using the URL with the below JSON,
{
"phoneNumber" : 188892,
"name" : "kikiki" ,
"email" : "loa@gmail.com",
"purpose" : "Business",
"hostName" : "sjs S Murthy"
}
im getting HTTP Status 415 – Unsupported Media Type.
why would that be?
java json spring rest http-status-code-415
New contributor
May be you are missingAccept: application/json
in the HTTP request?
– Ken Chan
20 hours ago
how you are calling the rest service, I mean r u using postman?? check your content type there
– Rezwan
20 hours ago
nope, sending request through postman, have sent the request ussing application/json header.
– Kiran S
20 hours ago
yes , added content type- appplication/json
– Kiran S
20 hours ago
add a comment |
@RestController
@RequestMapping(value="/uri",produces = "application/json",
consumes="application/json")
public class VisitorService {
VisitorDAO vis=new VisitorDAO();
@RequestMapping(value = "/ex" ,method = RequestMethod.POST)
public String showDetails(@RequestBody VisitorDTO visitor){
vis.addVisitorEntry(visitor);
return "success"+visitor;
}}
Above is my rest service.
whenever I hit a post using the URL with the below JSON,
{
"phoneNumber" : 188892,
"name" : "kikiki" ,
"email" : "loa@gmail.com",
"purpose" : "Business",
"hostName" : "sjs S Murthy"
}
im getting HTTP Status 415 – Unsupported Media Type.
why would that be?
java json spring rest http-status-code-415
New contributor
@RestController
@RequestMapping(value="/uri",produces = "application/json",
consumes="application/json")
public class VisitorService {
VisitorDAO vis=new VisitorDAO();
@RequestMapping(value = "/ex" ,method = RequestMethod.POST)
public String showDetails(@RequestBody VisitorDTO visitor){
vis.addVisitorEntry(visitor);
return "success"+visitor;
}}
Above is my rest service.
whenever I hit a post using the URL with the below JSON,
{
"phoneNumber" : 188892,
"name" : "kikiki" ,
"email" : "loa@gmail.com",
"purpose" : "Business",
"hostName" : "sjs S Murthy"
}
im getting HTTP Status 415 – Unsupported Media Type.
why would that be?
java json spring rest http-status-code-415
java json spring rest http-status-code-415
New contributor
New contributor
edited 19 hours ago
New contributor
asked 20 hours ago
Kiran S
33
33
New contributor
New contributor
May be you are missingAccept: application/json
in the HTTP request?
– Ken Chan
20 hours ago
how you are calling the rest service, I mean r u using postman?? check your content type there
– Rezwan
20 hours ago
nope, sending request through postman, have sent the request ussing application/json header.
– Kiran S
20 hours ago
yes , added content type- appplication/json
– Kiran S
20 hours ago
add a comment |
May be you are missingAccept: application/json
in the HTTP request?
– Ken Chan
20 hours ago
how you are calling the rest service, I mean r u using postman?? check your content type there
– Rezwan
20 hours ago
nope, sending request through postman, have sent the request ussing application/json header.
– Kiran S
20 hours ago
yes , added content type- appplication/json
– Kiran S
20 hours ago
May be you are missing
Accept: application/json
in the HTTP request?– Ken Chan
20 hours ago
May be you are missing
Accept: application/json
in the HTTP request?– Ken Chan
20 hours ago
how you are calling the rest service, I mean r u using postman?? check your content type there
– Rezwan
20 hours ago
how you are calling the rest service, I mean r u using postman?? check your content type there
– Rezwan
20 hours ago
nope, sending request through postman, have sent the request ussing application/json header.
– Kiran S
20 hours ago
nope, sending request through postman, have sent the request ussing application/json header.
– Kiran S
20 hours ago
yes , added content type- appplication/json
– Kiran S
20 hours ago
yes , added content type- appplication/json
– Kiran S
20 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Check that you have set the @EnableWebMvc
annotation in a @Configuration class.
Also, try adding the following dependencies to your pom.xml (if not using Maven, just add them to your classpath however you prefer).
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
Spring uses Jackson and Jackson-databind to parse the request's JSON body into a Java Object.
New contributor
have used xml based configuration
– Kiran S
19 hours ago
Try adding this to your xml config:<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.
– gbandres
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Kiran S is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942991%2frestful-web-service-415%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Check that you have set the @EnableWebMvc
annotation in a @Configuration class.
Also, try adding the following dependencies to your pom.xml (if not using Maven, just add them to your classpath however you prefer).
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
Spring uses Jackson and Jackson-databind to parse the request's JSON body into a Java Object.
New contributor
have used xml based configuration
– Kiran S
19 hours ago
Try adding this to your xml config:<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.
– gbandres
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
add a comment |
Check that you have set the @EnableWebMvc
annotation in a @Configuration class.
Also, try adding the following dependencies to your pom.xml (if not using Maven, just add them to your classpath however you prefer).
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
Spring uses Jackson and Jackson-databind to parse the request's JSON body into a Java Object.
New contributor
have used xml based configuration
– Kiran S
19 hours ago
Try adding this to your xml config:<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.
– gbandres
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
add a comment |
Check that you have set the @EnableWebMvc
annotation in a @Configuration class.
Also, try adding the following dependencies to your pom.xml (if not using Maven, just add them to your classpath however you prefer).
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
Spring uses Jackson and Jackson-databind to parse the request's JSON body into a Java Object.
New contributor
Check that you have set the @EnableWebMvc
annotation in a @Configuration class.
Also, try adding the following dependencies to your pom.xml (if not using Maven, just add them to your classpath however you prefer).
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version> // 2.4.3
</dependency>
Spring uses Jackson and Jackson-databind to parse the request's JSON body into a Java Object.
New contributor
New contributor
answered 19 hours ago
gbandres
825
825
New contributor
New contributor
have used xml based configuration
– Kiran S
19 hours ago
Try adding this to your xml config:<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.
– gbandres
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
add a comment |
have used xml based configuration
– Kiran S
19 hours ago
Try adding this to your xml config:<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.
– gbandres
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
have used xml based configuration
– Kiran S
19 hours ago
have used xml based configuration
– Kiran S
19 hours ago
Try adding this to your xml config:
<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.– gbandres
19 hours ago
Try adding this to your xml config:
<mvc:annotation-driven />
, and you still need the Jackson libraries in your classpath.– gbandres
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
thanks mate , it worked!
– Kiran S
19 hours ago
add a comment |
Kiran S is a new contributor. Be nice, and check out our Code of Conduct.
Kiran S is a new contributor. Be nice, and check out our Code of Conduct.
Kiran S is a new contributor. Be nice, and check out our Code of Conduct.
Kiran S is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942991%2frestful-web-service-415%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
May be you are missing
Accept: application/json
in the HTTP request?– Ken Chan
20 hours ago
how you are calling the rest service, I mean r u using postman?? check your content type there
– Rezwan
20 hours ago
nope, sending request through postman, have sent the request ussing application/json header.
– Kiran S
20 hours ago
yes , added content type- appplication/json
– Kiran S
20 hours ago