Thizzer Thizzer - 10 months ago 63
Java Question

JAX-RS Post multiple objects

I have a method;

public void test(ObjectOne objectOne, ObjectTwo objectTwo)

Now I know I can post a single object in json format, just putting it into the body.
But is it possible to do multiple objects? If so, how?

Answer Source

The answer is no.

The reason is simple: This about the parameters you can receive in a method. They must be related to the request. Right? So they must be either headers or cookies or query parameters or matrix parameters or path parameters or request body. (Just to tell the complete story there is additional types of parameters called context).

Now, when you receive JSON object in your request, you receive it in a request body. How many bodies the request may have? One and only one. So you can receive only one JSON object.