Here is my requirement:
I tried searching on the net for some comprehensive example for this but could not find any. Can anyone help?
Java JSON RESTful Web Service Example Posted by: Saurabh Arora in restMarch 30th, 20160Views In this example we shall learn implementing RestfulWeb Service in Java where the data interchange format shall be JSON. 1. Introduction to RESTful Web Services RESTful Web Services follow RESTarchitecture which stands for REpresentational State Transfer.
First, fire up Netbeans and create a new Maven Web Application project. Give it a name of you choosing. Right off the bat, create a web.xml file by right clicking on the project and creating a new Standard Deployment Descriptor. This is the configuration file for the RESTful service mapping.
JSON Response in Web Service. To change a web service that is already written to provide a XML response or to create a new one, we need to add just two things. Use @Produces annotation and add the MIME type application/json. Add dependent JAR files to produce JSON response.
We need to add a “Header” with the request to the web service. Same RESTful web service is capable of producing XML response as we have added XML MIME type also in @Produces annotation.
Jersey is a JAX-RS implementation for building RESTful webservices.
Start with their tutorial. It's pretty easy.
http://jersey.java.net/nonav/documentation/latest/getting-started.html
Edit: Also, there's a great O'Riley book on the subject (shocking, I know); RESTful Java with JAX-RS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With