Solved

Handling json in url param

Posted on 2016-08-11
1
70 Views
Last Modified: 2016-08-13
HI,
In my spring web application i am having the following code :
 @RequestMapping(value = "")
    public ModelAndView newNote(@RequestParam(value = "noteEvent", required = false) String noteEvent, HttpServletResponse response, HttpServletRequest request) throws IOException {

        ObjectMapper mapper = new ObjectMapper();
        String chatId = "";
        if(noteEvent != null) {
            Bun bun = mapper.readValue(noteEvent, Bun.class);
            chatId = bun.getChat();
        }

Open in new window

This is bascially a get request handler and url will have noteEvent param which is actually a json string :
"name":"sdfsd","button":"sdfsd","userId":"u:guid1","userName":"sdfsd","chat":"u:sdf","chatName":"Ben sdf"}

If the requestBody was a json string i could have directly used it as a param to the function and since spring auto performs the conversion i would have got an object withouth having to deal with this mapper thing.
But here as the noteEvent is a url param i had to resort to using this approach.
Dont know if there is a way in spring to handle this.

Please suggest a better approach if possible.

Thanks
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 36

Accepted Solution

by:
mccarl earned 500 total points
ID: 41753623
I think the better approach would be to not have the JSON in the URL to begin with. As you mentioned, I would only have it as the request body. If you don't want in the body, then I would break out those JSON values into either URL query params or path params.
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question