4 Replies Latest reply: May 7, 2013 12:20 PM by 1007187 RSS

    JAX RS questions on POST with different payloads

    1007187
      Hello everyone,

      Could you tell me if it is the way to think (the philosophy) to have one method which accepts POST with JSON content being able to support 2 différents POST payload ?
      If the answer is yes, how to do this ? Do I need to use JAX RS provider to do so ? Could give me please a sample or a pointer to a sample ?

      Best Regards.
        • 1. Re: JAX RS questions on POST with different payloads
          r035198x
          Why not create a wrapper POJO that contains the 2 objects and post that instead.
          • 2. Re: JAX RS questions on POST with different payloads
            1007187
            Hello,

            Thanks for answering but this is not really my question.
            I want to know if 2 different payload can be sent on the same path.

            Let me explain. Imagine you have

            @POST
            @Path("/test")
            @Consumes(MediaType.APPLICATION_JSON)
            @Produces(MediaType.APPLICATION_JSON)
            public Response myPostMethod(...) {
            }

            where the payload can be either
            {
                 "singer":"MySongSinger",
                 "title":"Song Title"
            }

            or

            {
                 "author":"MyBookWriter",
                 "booktitle":"BookTitle"
            }


            The payload samples are quite simple but may have totally different json structure which can be handled by this method.

            So according to this, my initial questions are remaining ....

            Best Regards.
            • 3. Re: JAX RS questions on POST with different payloads
              r035198x
              That is not RESTFul. You should be manipulating a resource in rest calls. Think about this a bit more. What would be the type of your method parameter for the REST provider to automatically map to? Just expose different urls for the different payloads and use different DTOs as the params for each.
              • 4. Re: JAX RS questions on POST with different payloads
                1007187
                Hello,

                This is exactly why I have asked you this question: "Could you tell me if it is the way to think (*the philosophy*) to have one method which accepts POST with JSON content being able to support 2 différents POST payload ?"

                Because I have the strong feeling that is it is not RESTful and i just want to get a confirmation on this.

                So, thanks a lot for this confirmation :-)

                Best Regards.