how to write a rest controller to consume restful web services json request
How to Consume a Json Request,Coming from some other Application like ".Net" and i want to Consume that into my Java Application .
How to Consume this with Controller in Spring MVC .
Thanks
Shashank
java rest web-services spring-mvc
add a comment |
How to Consume a Json Request,Coming from some other Application like ".Net" and i want to Consume that into my Java Application .
How to Consume this with Controller in Spring MVC .
Thanks
Shashank
java rest web-services spring-mvc
Welcome to SO. Please review the welcome tutorial for SO, and How to ask...
– Jason Armstrong
Nov 28 '18 at 17:37
add a comment |
How to Consume a Json Request,Coming from some other Application like ".Net" and i want to Consume that into my Java Application .
How to Consume this with Controller in Spring MVC .
Thanks
Shashank
java rest web-services spring-mvc
How to Consume a Json Request,Coming from some other Application like ".Net" and i want to Consume that into my Java Application .
How to Consume this with Controller in Spring MVC .
Thanks
Shashank
java rest web-services spring-mvc
java rest web-services spring-mvc
asked Nov 28 '18 at 6:09
ShekhaRShekhaR
52
52
Welcome to SO. Please review the welcome tutorial for SO, and How to ask...
– Jason Armstrong
Nov 28 '18 at 17:37
add a comment |
Welcome to SO. Please review the welcome tutorial for SO, and How to ask...
– Jason Armstrong
Nov 28 '18 at 17:37
Welcome to SO. Please review the welcome tutorial for SO, and How to ask...
– Jason Armstrong
Nov 28 '18 at 17:37
Welcome to SO. Please review the welcome tutorial for SO, and How to ask...
– Jason Armstrong
Nov 28 '18 at 17:37
add a comment |
2 Answers
2
active
oldest
votes
If I'am able to understand your question then you are asking about how to Post JsonRequest to RestController, for that I'm attaching a code snippet and hope it helps.
Step1: Create a Model Class of that JSON Request.
Step2: Mark @RequestBody Annotation with Controller method to get that type of Object in Method argument.
@RequestMapping(value = "/getRequest", method = { RequestMethod.POST },
produces = {"application/json"})
public @ResponseBody Object getResponse(@RequestBody JsonRequest request) {
sysout("Json Body: "+request.toString());
}
add a comment |
you are basically asking how controllers work !! a controller's job is to handle any (JSON or ...) request to its services.
I suggest you read some articles about spring MVC and controllers to understand how it works.
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
https://www.in28minutes.com/spring-mvc-tutorial-for-beginners
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
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
});
}
});
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%2f53513162%2fhow-to-write-a-rest-controller-to-consume-restful-web-services-json-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If I'am able to understand your question then you are asking about how to Post JsonRequest to RestController, for that I'm attaching a code snippet and hope it helps.
Step1: Create a Model Class of that JSON Request.
Step2: Mark @RequestBody Annotation with Controller method to get that type of Object in Method argument.
@RequestMapping(value = "/getRequest", method = { RequestMethod.POST },
produces = {"application/json"})
public @ResponseBody Object getResponse(@RequestBody JsonRequest request) {
sysout("Json Body: "+request.toString());
}
add a comment |
If I'am able to understand your question then you are asking about how to Post JsonRequest to RestController, for that I'm attaching a code snippet and hope it helps.
Step1: Create a Model Class of that JSON Request.
Step2: Mark @RequestBody Annotation with Controller method to get that type of Object in Method argument.
@RequestMapping(value = "/getRequest", method = { RequestMethod.POST },
produces = {"application/json"})
public @ResponseBody Object getResponse(@RequestBody JsonRequest request) {
sysout("Json Body: "+request.toString());
}
add a comment |
If I'am able to understand your question then you are asking about how to Post JsonRequest to RestController, for that I'm attaching a code snippet and hope it helps.
Step1: Create a Model Class of that JSON Request.
Step2: Mark @RequestBody Annotation with Controller method to get that type of Object in Method argument.
@RequestMapping(value = "/getRequest", method = { RequestMethod.POST },
produces = {"application/json"})
public @ResponseBody Object getResponse(@RequestBody JsonRequest request) {
sysout("Json Body: "+request.toString());
}
If I'am able to understand your question then you are asking about how to Post JsonRequest to RestController, for that I'm attaching a code snippet and hope it helps.
Step1: Create a Model Class of that JSON Request.
Step2: Mark @RequestBody Annotation with Controller method to get that type of Object in Method argument.
@RequestMapping(value = "/getRequest", method = { RequestMethod.POST },
produces = {"application/json"})
public @ResponseBody Object getResponse(@RequestBody JsonRequest request) {
sysout("Json Body: "+request.toString());
}
answered Nov 29 '18 at 15:35
Nitin GaurNitin Gaur
646
646
add a comment |
add a comment |
you are basically asking how controllers work !! a controller's job is to handle any (JSON or ...) request to its services.
I suggest you read some articles about spring MVC and controllers to understand how it works.
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
https://www.in28minutes.com/spring-mvc-tutorial-for-beginners
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
add a comment |
you are basically asking how controllers work !! a controller's job is to handle any (JSON or ...) request to its services.
I suggest you read some articles about spring MVC and controllers to understand how it works.
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
https://www.in28minutes.com/spring-mvc-tutorial-for-beginners
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
add a comment |
you are basically asking how controllers work !! a controller's job is to handle any (JSON or ...) request to its services.
I suggest you read some articles about spring MVC and controllers to understand how it works.
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
https://www.in28minutes.com/spring-mvc-tutorial-for-beginners
you are basically asking how controllers work !! a controller's job is to handle any (JSON or ...) request to its services.
I suggest you read some articles about spring MVC and controllers to understand how it works.
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
https://www.in28minutes.com/spring-mvc-tutorial-for-beginners
answered Nov 28 '18 at 6:25
mohammadmohammad
84
84
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
add a comment |
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
Hi Mohammad, I Know Spring MVC ,i want to know how Rest Controller Works if any Json Request Coming to me(Java App). For Example : I Have a Json Request that is coming to me from Soap UI to get json and convert into java object into my Controller class , how this scenario work?
– ShekhaR
Nov 28 '18 at 6:38
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
You need to be more specific with the question. Break it down like this. - Problem statement. - What you have done to solve the problem. - Where you are stuck now.
– janardhan sharma
Nov 28 '18 at 6:41
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
if the request media type is JSON then when it gets to a service in the controller, spring MVC automatically convert JSON to the class that you have created before! you don't have to config anything spring would do that for you ! you only need to create the class that the JSON is gonna be mapped.
– mohammad
Nov 28 '18 at 6:43
add a comment |
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.
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%2f53513162%2fhow-to-write-a-rest-controller-to-consume-restful-web-services-json-request%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
Welcome to SO. Please review the welcome tutorial for SO, and How to ask...
– Jason Armstrong
Nov 28 '18 at 17:37