https://github.com/anicetkeric/sample_jersey_jackson
How to integrate Jersey with Jackson to develop RESTful JAX-RS services
https://github.com/anicetkeric/sample_jersey_jackson
Last synced: 6 months ago
JSON representation
How to integrate Jersey with Jackson to develop RESTful JAX-RS services
- Host: GitHub
- URL: https://github.com/anicetkeric/sample_jersey_jackson
- Owner: anicetkeric
- Created: 2016-12-09T10:03:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-26T20:47:31.000Z (about 2 years ago)
- Last Synced: 2023-09-27T04:35:05.201Z (about 2 years ago)
- Language: Java
- Size: 44.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sample_Jersey_Jackson
How to integrate Jersey with Jackson to develop RESTful JAX-RS services
We will learn how to integrate Jersey REST Client and Jackson to build a RESTful Web service which produces and consumes JSON Type. We use Jackson for convert Java Object to JSON and vice-versa in a JAX-RS Web Service.
Java: https://www.java.com/fr/download/
Eclipse for Java EE Developpers: http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/mars1
Apache Tomcat: http://tomcat.apache.org/
RESTClient# Project structure
# Jackson Dependencies
```xml
com.sun.jersey
jersey-server
1.9
com.sun.jersey
jersey-json
1.9
```
#### Web.xml (Contents)
```xml
RestServer-serlvet
com.sun.jersey.spi.container.servlet.ServletContainer
com.sun.jersey.api.json.POJOMappingFeature
true
1
RestServer-serlvet
/api/*
```
## Example UserService.class
```javaimport java.util.ArrayList;
import java.util.List;import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;import com.rest.service.entities.User;
@Path("/users")
public class UserService {@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public User getUser( @PathParam("id") int id ) {
User user = new User(id, "Anicet", 18);
return user;
}@POST
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public User postUser( @PathParam("id") int id ) {
User user = new User(id, "Eric", 25);
return user;
}@POST
@Path("/listUsers")
@Produces(MediaType.APPLICATION_JSON)
public List listUs() {List us = new ArrayList();
us.add(new User(1, "Aek", 18));
us.add(new User(2, "Keric", 20));
us.add(new User(3, "Anicet", 25));return us;
}}
```
## Demohttp://localhost:8088/RestfullJerseyJackson/api/users/listUsers
Output
