#Jersey #ContextResolver #SimpleModule

How to Customise the Jackson JSON ObjectMapper in Java EE Enterprise Application

Assume we have a naive User POJO class with a BSON Type ObjectId field, i.e., id. public class User { private ObjectId id; private String username; private String password; private Date createdAt; public getters/setters; ... We can expect the following outputs from our REST services which is not a String with 24 hex characters. { "_id": { "new": false, "machine": 805608948, "timeSecond": 1403022678, "inc": -871980150, "time": 1403022678000 }, "username": "John Smith", "password": "am9obiBzbWl0aCBwYXNzd29yZA", "createdAt": 1403022678341 } As we know, it can be solved by using the Jackson annotation for configuring Serializer class to serialize the associated value. ...

Author 3 min
#Java EE #Swagger #JAX-RS #Jersey

Integrating Swagger into JAX-RS with Java EE 6 specification

Introduction Swagger is an awesome framework we often used to describe, consume and visualize our RESTful web services. Typically, we use Tomcat with Jersey as a servlet, then specify the Swagger package and Swagger Configuration class into web.xml, finally annotate the resources, methods and models to complete the configurations. Our team recently built a Java EE 7 application for a RESTful web service. The goal of this article is to share our experiences of configuring Swagger in Glassfish 4 without a web. ...

Author 4 min
#Java #Jersey #Maven

Jersey Test Framework with Maven

Introduction This memo records the issues while executing the unit-test with Jersey Test framework. We use the Jersey framework to implement the RESTful Web services and employ the Maven to manage the dependencies in project. First of all, we add the jersey-test-framework-grizzly2 dependency to enable the test framework in pom.xml; Second, we deploy the application using Jersey specific servlet in web.xml. Finally, we have the following java files within Maven Archetype – maven-archetype-webapp: ...

Author 4 min
#Java #Jersey #Restful

A Jersey POJOMapping Example in Mapping Form Parameters

Jersey, RESTful Web Services in Java. In Java Servlet circumstance, we usually harvest the form parameters by using request.getParameter(“FORM_FIELD_NAME”) syntax. Now we can do it more elegant while enabling Jsersey’s POJOMapping features. The following example demonstrates the account registration scenario. Here we have a Account class, i.e., Account.java: public class Account { private String email; @JsonProperty("email") public String getEmail() { return email; } public void setEmail(String email) { this. ...

Author 2 min