I want to send response containing only requested fields for GET API. Reducing total size of response.
Example, Default behavior, when to specific fields requested:
GET /v1/users/
{
"data" :
[
{
"name" : "User1",
"phone" : "800-999-9999",
"city" : "XYZ1",
"country" : "PQR1"
},
{
"name" : "User2",
"phone" : "800-999-9999",
"city" : "XYZ2",
"country" : "PQR2"
}
]
}
Use case, where fields needed are passed as query parameters
GET /v1/users/?fields=name,city
{
"data" :
[
{
"name" : "User1",
"city" : "XYZ1"
},
{
"name" : "User2",
"city" : "XYZ2"
}
]
}
Came across "https://github.com/monitorjbl/json-view". But was shot down by the team.
How can I implement this functionality using spring boot? How do organizations using java microservices implement this feature?