title: Gson how to deserialise null object property
body: <p>I have some json, with a sequence of entries which look like this (I've simplified it tofocus on relevant issue which is why it looks a little redundant):</p>
  
  <blockquote>
    <p>{"name":"ISPC Seychelles","company":{"name":"ISPC
    Seychelles","id":3427640}}</p>
  </blockquote>
  
  <p>sometimes however the company property is set to null:</p>
  
  <blockquote>
    <p>{"name":"Westin Miyako Kyoto", "company":null}</p>
  </blockquote>
  
  <p>I have defined my classes like this (sorry for the public access modifiers, will change these when I get this bit of code working :)) :</p>
  
  <pre><code>class Entry {
    public String name=;
    public Company company;
    public String toString() {
        return  name + ";" + company;
    }
  }
  
  class Company {
      public String name;
      public int id;
      public String toString() {
          return "Company: " + name;
      }
  }
  </code></pre>
  
  <p>In my code, I try to use gson to deserialise the JSON contained in the variable called output:</p>
  
  <pre><code>while ((output = br.readLine()) != null) {
      Gson gson = new Gson();
      Reply reply = gson.fromJson(output, Reply.class); 
      Entry[] entries = reply.entries;
      for (int i=0; i &lt; entries.length; i++) {
          System.out.print(entries[i]+ "\n") ;
      }
  }
  </code></pre>
  
  <p>This works fine when the company element is populated as in the first example in the JSON:</p>
  
  <blockquote>
    <p>ISPC Seychelles;Company: ISPC Seychelles</p>
  </blockquote>
  
  <p>However, if the element is not populated as in the second example, I get the following output:</p>
  
  <blockquote>
    <p>Westin Miyako Kyoto; null</p>
  </blockquote>
  
  <p>What I would like is the following output:</p>
  
  <blockquote>
    <p>Westin Miyako Kyoto; Company: null</p>
  </blockquote>