Posts by Sjoerd Schunselaar
When we want to clone an object there are several ways to do this For instance we can implement Clonable, which makes it possible to duplicate an object. We also can create a new object manually by calling each setter or use a parameterised constructor. In case we want to clone a Hibernate object, there is an extra option available which is more elegant: the Hibernate3BeanReplicator. The Hibernate3BeanReplicator is provided by Beanlib (http://beanlib.sourceforge.net/) and it supports deep clones, so we can also clone related one-to-one objects easily. For example we want to clone the Student object, including all child (one-to-one) objects.
While writing unit tests, you often have to mock dependencies like services or controllers. Often a constructor is used to autowire the dependencies as shown in the example below. In the Test class I instantiated the ContactService using a contactRepository Mock object
Spring made it very easy to consume JSON webservices. In this article I describe how to receive and parse JSON and how to send your Java objects as JSON. First we need to include the required dependencies. If you use maven, include the following dependencies: