This post explains de-serialization of java objects to JSON using new Java JSONB api. We need the following jars to run the below example 1) javax.json-1.1.jar 2) jsonb-api-1.0.0.jar 3) yasson-1.0.jar yasson-1.0.jar is reference implemenation which can be obtained from the below link http://json-b.net/download.html In this example we will de-serialize the Person object, below is the…… Continue reading Deserialization of java objects from JSON
Serialization of Java objects to JSON
This post explains serialization of java objects to JSON using new Java JSONB api. We need the following jars to run the below example 1) javax.json-1.1.jar 2) jsonb-api-1.0.0.jar 3) yasson-1.0.jar yasson-1.0.jar is reference implemenation which can be obtained from the below link http://json-b.net/download.html In this example we will serialize the Person object, below is the…… Continue reading Serialization of Java objects to JSON
Retrieving url template parameters in JAX-RS annotated method
In JAX-RS, we can create url templates in the format as shown below http://localhost:8080/JAXRSConcepts/myresources/webresource4/retrieveRecord1/ {parameter_name} where anything between ‘{‘ and ‘}’ acts as places where we can provide parameters when creating the actual url. The name between ‘{‘ and ‘}’ in url template will act as the parameter name. In the actual url the text…… Continue reading Retrieving url template parameters in JAX-RS annotated method
Retrieving header parameters in JAX-RS annotated method
The post explains different ways of retrieving header parameters in JAX-RS annotated method. Below is the complete code 1 package resource; 2 3 import javax.ws.rs.GET; 4 import javax.ws.rs.HeaderParam; 5 import javax.ws.rs.Path; 6 import javax.ws.rs.core.Context; 7 import javax.ws.rs.core.HttpHeaders; 8 import javax.ws.rs.core.MediaType; 9 import javax.ws.rs.core.Response; 10 11 @Path(“webresource3”) 12 public class WebResource3 { 13 @GET 14 @Path(“headerParameters1”)…… Continue reading Retrieving header parameters in JAX-RS annotated method
Creating dependent tasks
In this post of gradle, I will show two different ways to make one task depend upon other. build.gradle 1 task task1 { 2 doFirst { 3 println ‘I am dependee’ 4 } 5 } 6 7 task task2(dependsOn: task1) { 8 doFirst { 9 println ‘I am dependent1’ 10 } 11 } 12 13…… Continue reading Creating dependent tasks
Retrieving query parameters in JAX-RS annotated method
The post explains different ways of retrieving query parameters in JAX-RS annotated method. Below is the complete code 1 package resource; 2 3 import javax.ws.rs.GET; 4 import javax.ws.rs.Path; 5 import javax.ws.rs.QueryParam; 6 import javax.ws.rs.core.Context; 7 import javax.ws.rs.core.MediaType; 8 import javax.ws.rs.core.Response; 9 import javax.ws.rs.core.UriInfo; 10 11 @Path(“webresource2”) 12 public class WebResource2 { 13 @GET 14 @Path(“queryParameters1”)…… Continue reading Retrieving query parameters in JAX-RS annotated method
Simple JsonPatch Example
JsonPatch is a format for storing a sequence of operations that has to be applied on the target json structure. The following operations can be stored in JsonPath and operated on json structure 1) add 2) remove 3) replace 4) move 5) copy 6) test Java jdk provides api for creating JsonPatch. The post explains…… Continue reading Simple JsonPatch Example
Creating and executing task
Gradle is domain specific language where the domain in this case is automating application build process. Gradle consists of Projects and Tasks. Each project has multiple Tasks and each Task has multiple actions. In this post I will explain how to create and execute task. Create a file by name build.gradle with the below code…… Continue reading Creating and executing task
Marshaling a property as xml attribute
By default when marshaling to xml file, all properties are marshaled as elements. This default behaviour can be changed and this post explains how to do it. In this post I will marshall the below java bean class, and id property as its attribute. Country 1 package package1; 2 3 import javax.xml.bind.annotation.XmlAttribute; 4 import javax.xml.bind.annotation.XmlRootElement;…… Continue reading Marshaling a property as xml attribute
Preventing a property from being marshalled to xml file
By default all properties of an instance are marshalled as elements in an xml file. As shown below.. Marshalling an Country insance with below class structure Country package package2; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Country { private int id; private String name; private int population; public int getId() { return id; } public void setId(int…… Continue reading Preventing a property from being marshalled to xml file