how to write a rest controller to consume restful web services json request












-4















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










share|improve this question























  • Welcome to SO. Please review the welcome tutorial for SO, and How to ask...

    – Jason Armstrong
    Nov 28 '18 at 17:37
















-4















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










share|improve this question























  • Welcome to SO. Please review the welcome tutorial for SO, and How to ask...

    – Jason Armstrong
    Nov 28 '18 at 17:37














-4












-4








-4








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












2 Answers
2






active

oldest

votes


















0














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());
}





share|improve this answer































    0














    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






    share|improve this answer
























    • 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











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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());
    }





    share|improve this answer




























      0














      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());
      }





      share|improve this answer


























        0












        0








        0







        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());
        }





        share|improve this answer













        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());
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 '18 at 15:35









        Nitin GaurNitin Gaur

        646




        646

























            0














            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






            share|improve this answer
























            • 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
















            0














            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






            share|improve this answer
























            • 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














            0












            0








            0







            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






            share|improve this answer













            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







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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



















            • 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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)