maury844
maury844

Reputation: 1250

Sending multiple objects in HTTP Request (Spring)

I'm currently "migrating" from SOAP to REST services. (legacy code)

There are several methods that send objects in the request, the objects vary in type and number, I'd like to do something like this.

public long getRelationship(@RequestBody RelationshipDirection relationshipDirection,
@RequestBody List<long> ids, @RequestBody BigInteger skipCount){
    /*do something*/
}

And then there is another method that needs just 2 objects, and one is 'Extension' type.

From similar questions I know that I need a wrapper object, but I would need one for each possible combination of parameter number and types, so my question here is:

Is there another solution for this? , something like a "Generic container"?

Upvotes: 1

Views: 1516

Answers (1)

so-random-dude
so-random-dude

Reputation: 16465

How about this ?

@RequestMapping(
    value = "/some-post-endpoint", 
    method = RequestMethod.POST)
public void post(@RequestBody Map<String, Object> payload) 
    throws Exception {

  System.out.println(payload);

}

I think Map is a generic enough container.

Upvotes: 3

Related Questions