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
Setting Filter at Logger level
In the post “Setting Filter at Handler level”, I showed how to set filter at handler level. In this post I will explain how to set filter at logger level. An use case of setting filter at logger level, is restricting logging of messages based on the user who logged it. Custom Filter 1 package…… Continue reading Setting Filter at Logger level
Setting Filter at Handler level
Java logging provides log levels at logger and handler level, to filter the messages. To make sure only required messages are logged. We can extend this functionality and provide our own filter, which will filter messages based on message’s metadata in addition to filtering by log levels. We can add this filter at logger level…… Continue reading Setting Filter at Handler level
Supplier Functional Interface Example
Java 8 added a new functional interface named “Supplier”. The purpose of this interface is to supply instances. I will be explaining using the below example. In the example I have want of list of employees. I will separate the logic behind employee instance creation and adding to list. The employee instance will be created…… Continue reading Supplier Functional Interface Example
Consumer Functional Interface Example
Java 8 added a new functional interface named “Consumer”. The purpose of this interface is to consume/process the information received, it doesn’t return anything. I will be explaining using the below example. In the example I have list of employees whom I want to terminate. I will pass the list of employees to an implementation…… Continue reading Consumer Functional Interface Example
BiPredicate Simple Example
This post explains BiPredicate functional interface. BiPredicate is similar to Predicate functional interface except BiPredicate takes two arguments instead of one. In the below example we will filter list of Person entities based on first and last name. The predicate class name will be “NamePredicate”. NamePredicate package Function; import java.util.function.BiPredicate; public class NamePredicate implements BiPredicate…… Continue reading BiPredicate Simple Example
Different ways to convert collection to an array
This post explains two ways through which we can convert a collection to an array. The collection can be a list or set. First approach is simply calling “toArray” on collection instance. This method returns an Object array, When converting to array it doesn’t consider the data type of the entries in the collection. Below…… Continue reading Different ways to convert collection to an array