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

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