0

I am quite new to Spring Boot and REST API. I am trying to build a simple REST API that deals with arbitrary JSON data. I got it working to the point where I can use GET and POST.

What I would want to achieve is to send the same data back with an additional field added. If the data is this(Can be arbitrary).

{
    "firstname" : "Dheeraj",
    "lastname"  : "Dhall"
}

I would want something like this back.

{
    "id": "1"
    "firstname" : "Dheeraj",
    "lastname"  : "Dhall"
}

The method that handles PUT request has JsonNode as the parameter and my model is something like this

public class Person {
    private Long id;
    private Map<String, String> map;
}

So in the method that handles the PUT request I create a map and load data from the JSON Object. So the problem is that my response is something like this

{
    "id": "1"
    "map":{
             "firstname" : "Dheeraj",
             "lastname"  : "Dhall"
          }
}

How do I get it to print without a "map"? what is the best way to handle arbitrary JSON data?

3

1 Answer 1

0

Why do you need to use Map in your Person class? I think you don't need to use Map in this case, you can change your Person class like below:

public class Person {
    private Long id;
    private String firstname;
    private String lastname;
}  
Sign up to request clarification or add additional context in comments.

1 Comment

The data that I receive is arbitrary. There can be multiple fields, I gave that as an example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.