1

is it possible to support this JSON in Spring? Without create new object in java, maybe Map?

JSON:

{   
    "object":"1",
    "list":[
               {
                  "id":"1"
               }
            ]
}

Java:

@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Map<String, Object>> getRecipe(@RequestBody What should I write in this place?){

1 Answer 1

1

Yes, you can do that using HashMap like below but why do you want to do that? You should create separate JavaBean class for request with properties required by REST service.

    @RequestMapping(value = "/upload/one", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Map<String, Object>> getRecipe(@RequestBody HashMap<String, Object> request){
        System.out.println(request);
        return null;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

I was curious how to do it

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.