I have a problem with nullPointer
in getter method.
Here is the code:
public String getTitle()
{
if(!title.isEmpty())
return title;
else
return "foo";
}
When I change this to normal getter it works perfectly.
public String getTitle()
{
return title;
}
Where is the trick? Is there a reflection trick?
UPDATE The problem is not null checking, but excecuting getter without calling it
STACKTRACE
org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]- >si.mikropis.webkiosk.model.vao.wine.Wine["title"])
Caused by: java.lang.NullPointerException
at si.mikropis.webkiosk.model.vao.base.BaseModel.getTitle(BaseModel.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:483)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:418)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
... 32 more