0

Hi I am new to spring.

I am facing problem in mapping json object from angular to Map in spring controller. The definition of my controller is as follows :-

@RequestMapping(value="/PnPanel.go/FlowSheets/data/*", method={RequestMethod.GET, RequestMethod.POST},
                        consumes="application/json", produces="application/json")
public @ResponseBody Map invokeFlowsheets
(
    HttpServletRequest request, 
    @RequestBody Map<String, Map> req
)

My Request body looks like

{"reqParams":"{\"name\":\"sachin\"}","appParams":"{\"name\":\"sachin1\"}","otherInfo":"{\"name\":\"sachin2\"}"}

As you can see, I am sending nested json objects and I want to map them into java.util.Map, But I am getting 400 error from spring telling that request was syntactically bad.

Sorry for bad english and for such a silly question.

Thanks in advance.

3
  • clearly you are using something to perform the JSON mapping; perhaps jackson. Write a test class that uses your JSON mapping library directly. This should help you debug your problem. Also, consider generating example JSON with the JSON mapping library. The JSON you included does not match a map<String, Map>. it is an object with three string parameters (that happen to contain json in the string values). Commented Jan 28, 2016 at 7:27
  • first of all change your req object as Map<String,Object>. 400 means you are not sending a required parameter. Could you please share how do you send this request to the spring controller ? Commented Jan 28, 2016 at 7:34
  • Please post the clientside code that sends the ajax request. Commented Jan 28, 2016 at 10:33

1 Answer 1

1

Modify your JSON string into :

{"reqParams":{"name":"sachin"},"appParams":{"name":"sachin1"},"otherInfo":{"name":"sachin23"}}

Notice that {} are not surrounded with "".

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

Comments

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.