Posts

Showing posts from March, 2016

Singleton Design Pattern for Utility Clases

public class DateUtility {   private static DateUtility instance;         public static DateUtility getInstance() {    synchronized (DateUtility.class) {      if (instance == null) {        instance = new DateUtility();      } } return instance; }  public String convertDateToString(Date date) { ....................................... } } Usage : DateUtility.getInstance().convertDateToString();

Add PMD rules into your project

pom.xml <properties>              <pmd.failOnViolation>true</pmd.failOnViolation> </properties> <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-pmd-plugin</artifactId>             <version>3.1</version>             <executions>               <execution>                 <id>pmd</id>                 <phase>verify</phase>               ...

Convert XSD element choice with "maxOccurs=unbounded" into individual list of objects

Problem defined here: http://archive.oreilly.com/pub/a/onjava/2003/12/10/jaxb.html?page=2 Plugins used: https://github.com/highsource/jaxb2-basics/wiki/JAXB2-Simplify-Plugin XSD Sample <xs:schema xmlns:tns="http://www.omnicogroup.com/FPF/namespace" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.omnicogroup.com/FPF/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema">   <xs:element  name="transaction">     <xs:complexType>       <xs:sequence>         <xs:choice maxOccurs="unbounded">           <xs:element  name="TransactionDetails">             <xs:complexType>               <xs:sequence>        ...

RESTful API + POST + json body

Library :        <dependency>             <groupId>com.fasterxml.jackson.core</groupId>             <artifactId>jackson-databind</artifactId>             <version>2.7.2</version>         </dependency> Mapper Class public class MapperUtil {     private final static ObjectMapper mapper = new ObjectMapper();     public static <T> T readAsObjectOf(Class<T> clazz, String value) {         try {             return mapper.readValue(value, clazz);         } catch (IOException e) {             logger.error(e.getMessage());      ...