annotation or some automated code generation for setting default values to avoid NullPointerExceptions in Android/Java?
<p>I want to know if in Android there is any design pattern,third part library or any Annotation processors that handles null?</p>

<p>For example, let's say you parse a <code>JSON Response</code> using <code>Gson</code> and maps the response string directly to an <code>Object named "Person"</code> with Gson.</p>

<pre><code>Now assume Person has 3 fields
1) Name
2) Age
3) Gender
</code></pre>

<p>and you are about to display them on UI, my Question is how I can avoid a <code>NULL pointer Exception without checking for Nulls for each field when displaying this data.</code></p>

<p>Is there an Annotation Processor or any library that allows you to provide null replacement values? Something like this</p>

<pre><code>@defVal("N/A")
private String name;
@defVal(0)
private int age;
@defVal("N/A")
private String gender;
</code></pre>

<p>so we can avoid null check statements for all these fields and when calling there getters it provides the value if exists if there is null then provides default values. Any Suggestions?</p>

<p><strong>EDIT:</strong> I know the two ways for handling Null Pointer crash </p>

<pre><code>1) to use try catch 
2) to use Getters and inside every getter i should check the null value and sets a default value if there is null
</code></pre>

<p><strong>But My Question is is there a way to reduce these lines of code and use some auto generation thing? Some kind of Annotations I believe</strong></p>