Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4062

Pass multiple JSON data in Request Body of Postman and Get into Java Rest API using Jersy(JXRS)

$
0
0

I want to get multiple JSON data which I am passing into Postman in Body as Json format.

If I am passing single json data like : "{"firstName":"riya","lastName":"soni"}" so I can get it in my Java API mentioned as below :

@Path("patient")@POST@Consumes(MediaType.APPLICATION_JSON)public String getPatient(Patient patient) {System.out.println(patient.getFirstName());System.out.println(patient.getLastName());return "ok";}

It is working properly. But if I want to pass data like [{"firstName":"riya","lastName":"soni"},{"firstName":"shreya","lastName":"patel"}]

and getting in API like below :

@Path("patientDetail")@POST@Consumes(MediaType.APPLICATION_JSON)public String getPatientDetails(@RequestBody List<Patient> patient) {for (Patient p : patient) {System.out.println(p.getFirstName());System.out.println(p.getLastName());}return "ok";}

When I am hitting request from postman by passing multiple JSON data as I have mentioned, even getPateintDetails method is not calling, how to pass and get multiple json data in Rest API. Please give me the solution or reference link for the same.


Viewing all articles
Browse latest Browse all 4062

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>