I am trying to create an immutable object using Jersey Java. But I don't know if the default constructor is useful or not in a big application. Can someone guide me on this.
This is my class :-
package com.jersey.jaxb;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;
@XmlRootElement
@XmlType(name="todo")
@XmlAccessorType(XmlAccessType.FIELD)
@AutoProperty
public class Todo {
@XmlElement(name="summary")
private final String summary;
@XmlElement(name="description")
private final String description;
public String getSummary() {
return summary;
}
public String getDescription() {
return description;
}
private Todo(){
this(new Builder());
}
private Todo(Builder builder){
this.summary = builder.summary;
this.description = builder.description;
}
@Override
public boolean equals(Object o) {
return Pojomatic.equals(this, o);
}
@Override
public int hashCode() {
return Pojomatic.hashCode(this);
}
@Override
public String toString() {
return Pojomatic.toString(this);
}
public static class Builder{
private String description;
private String summary;
public Builder summary(String summary){
this.summary = summary;
return this;
}
public Builder description(String description){
this.description = description;
return this;
}
public Todo build(){
return new Todo(this);
}
}
}
So does the default constructor:-
private Todo(){
this(new Builder());
}
help in serialization/de-serialization or its of no use at all.
I don't know what effects will it have in a big application or should I not use it all.