Jibx Jersey2 Integration

by Prasanth Gullapalli

Jersey2 provides inbuilt support for Jackson and JAXB. But Jibx is not supported by default. To use Jibx in conjunction with Jersey2, we are taking the XML input as a stream and after receiving the request, we are parsing it using Jibx. But there is actually a better way of achieving the same using MessageBodyReader and MessageBodyWriter APIs. Continue reading


Which is better option: Cloning or Copy constructors?

by Prasanth Gullapalli

Here is how I started writing this article. I have read this statement so many times: “Cloning becomes difficult when the object has references to mutable final fields.” And every time I google about it, understand what exactly this means and as part of the process forget about it too. So thought I would blog this so that this will serve as my immediate reference.

Cloning an object, what I could recall from my OOP course in my graduate studies, is creating a similar copy of an object which basically should conform to the following rules:

(1) x.clone() != x
(2) x.clone().getClass() == x.getClass()
(3) x.clone().equals(x) Continue reading

JMX and MBeans with Spring

by Prasanth Gullapalli

JMX defines an architecture for management and monitoring of long running Java applications. Simply put, it provides an interface for interacting with a running application. So through JMX, we can check/change the state of variables or to invoke a method in a (remote) running application via a management GUI such as JConsole. Continue reading

Type Conversion in Spring

by Prasanth Gullapalli

Here are few straight cases where we need type conversion:
Case #1. To help simplifying bean configurations, Spring supports conversion of property values to and from text values. Each property editor is designed for a property of certain type only. And to put them in use, we have to register them with Spring container.
Case #2. Also when using Spring MVC, controllers binds the form field values to properties of an object. Suppose the object is composed with another object, then the MVC controller cannot automatically assign values to the internal custom type object as all the values in the form are inputted as text values. Spring container will take of conversion of text values to primitive types but not to custom type objects. For this to be taken care, we have to initialize custom editors in the MVC flow.

This article will discuss the various ways of implementing the converters for custom type objects. Continue reading

More on Serialization

by Prasanth Gullapalli

Serialization is all about saving the state of a given object and reconstructing the object back when it is needed. As it is all about saving state of an instance, it is clear that none of the static variables would get serialized as part of the process. Also when we want few variables defined in an object not to be serialized, we mark them as transient. For ex: we don’t want to serialize a database connection. Continue reading

Natural Ids in Hibernate

by Prasanth Gullapalli

A natural id is a property or a set of properties that would identify an entity uniquely. We can have at-most one natural id defined for an entity. When Hibernate sees natural-id tag in an entity mapping file, it automatically creates unique and not-null constraints on the properties constituting natural-id. Continue reading