1

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"?

2
  • This is a complicated question without knowing more details. Are you saying its impossible to know which objects are in a given request without examining the request body? Commented Oct 2, 2017 at 21:24
  • and how your SOAP request looks like? is there Root element, isn't it? And answer no, there is no such thing like "Generic container" if you do not define it. And it will be that "wrapped object" anyway. Commented Oct 2, 2017 at 21:27

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have to test it but for now, Map seems to be working fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.