Solved

Handling json in url param

Posted on 2016-08-11
1
42 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
1 Comment
 
LVL 35

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now