-2

In one of the interview I was asked below question

URI student/1

suppose 1 is Roll number of the student and we get a response like

{ "sname" : "abc", "sBloodGroup" : "o pos", "age" : "30", "some extra fileds" : "xyz", ... ... }

Now task is to create a rest api where user can give multivalue parameter and response should have only required fields as requested.

URL : student/1?fieldName=sname,age { sname : "abc" age : "30" }

how can we design such problem?

Rituraj Sharma
  • 111
  • 1
  • 5
  • 2
    Duplicate of https://stackoverflow.com/questions/9314735/how-to-return-a-partial-json-response-using-java – grekier Aug 03 '21 at 12:49

1 Answers1

-1

If you are using noSql DB like MongoDB you can use the fieldname as projections and the same document you can parse to json and return back in api response.

like:

db.student.find({id:1},{_id:0,sname:1,age:1})

it will return you only the required json

rohit saraf
  • 37
  • 1
  • 8