Posts

Showing posts from August, 2022

Include Null or Empty Attributes in Response of Jax-Rs Rest Service

Image
 By Default when the response has empty or null attributes it is removed from the response structure to reduce payload size and to improve performance. But there are times when a complete structure is needed despite its attributes having a null or empty value. Below process shows how to modify a Jax-Rs application to include null or empty attributes in response structure. Create a sample Jax-Rs Application                     Create a basic Jax-Rs Application Add another param (param3) to both request and response structure and create a pojo class for the same Request: Response : Now in Sample Rest service add logic to map the Request param3 attribute to Response param3 attribute, this way we can test the Service by passing null as input parameters to check the response In most of the cases this is what may be expected but in some cases we may want to have all attributes as part of response despite having a null value. For...

Modify URL for Jax-Rs Application

Image
 T here are multiple ways to do this, in this blog i will show 2 main approach to do the same Method1 : To Modify Application Class Create a sample Jax-Rs Application                Create a basic Jax-Rs Application Modify Application path in RestApplication Compile and run Method 2 : Although above approach does the job but it has a drawback wherein when we create a new service we need to register the same in our Application Class. As the number of services grow this process may become lengthy and tedious , hence we edit our Application class to include all services inside our specified package and Modify web.xml file to customize the url. Modify RestApplication to include packages Modify web.xml to customize Rest url Compile and Run