0

I am trying to identify the data format of retrieving data in a REST end point. I planning to only give response for request that having JSON data format when API is calling. From the retrieved header I am planning to identify that.

I am defining the end point is like following structure:

@PostMapping("/login/checkAuthorization")
  public PrivillegeResponse  checkAuthorizationAction(@RequestBody 
       PrivillegeModel privillegeObj ) 
        {
          //codes to be executed
           //giving JSON response
        }

Before giving its business logic implementation , I need to verify that the data retrieved is JSON data. What are the possibilities to achieve these functionalities?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mr.DevEng
  • 2,651
  • 14
  • 57
  • 115

1 Answers1

1

For SpringBoot , you need to define the Class with @RestController .

For restricting it to Json , just define the consumes="application/json" attribute .

You can refer to ::

Producing and consuming custom JSON Objects in Spring RESTful services

For a Generic Approach,check Spring RequestMapping for controllers that produce and consume JSON

1nullpointer
  • 1,212
  • 1
  • 13
  • 19