title: How to handle different data types with same attribute name with Gson?
body: <p>I'm currently writing an RSS feed parser in Java utilizing Gson. I'm converting the RSS' XML into JSON, and then subsequently using Gson to deserialize the JSON into Java POJOs (somewhat roundabout but there's a reason for it). Everything was working fine as far as deserializing for the feed #1 (<strong>BBC</strong>) listed below, but for the feed #2 (<strong>NPR</strong>) listed below, I started getting exceptions being thrown.</p>
  
  <p>I think I have identified the problem, but I'm uncertain as to how to resolve it:</p>
  
  <hr>
  
  <p>The issue is arising with these two RSS Feeds (for example):</p>
  
  <ol>
  <li><a href="http://feeds.bbci.co.uk/news/rss.xml" rel="noreferrer">http://feeds.bbci.co.uk/news/rss.xml</a></li>
  <li><a href="http://www.npr.org/rss/rss.php?id=1001" rel="noreferrer">http://www.npr.org/rss/rss.php?id=1001</a></li>
  </ol>
  
  <p>For these different RSS feeds, a field called "guid" is being returned as either a) <em>an object</em> with 2 fields (as in the <strong>BBC RSS</strong> Feed) or b) <em>a string</em> (as in the <strong>NPR RSS</strong> Feed).</p>
  
  <p>Here's some paraphrased versions of the relevant JSON:</p>
  
  <p><strong>BBC RSS Feed</strong></p>
  
  <pre><code>// is returning 'guid' as an object
  "item" : 
  [
      {
          // omitted other fields for brevity
          "guid" : {
              "isPermalink" : false,
              "content" : "http:\/\/www.bbc.co.uk\/news\/uk-england-33745057"
          },
      },
      {
          // ...
      }
  ]
  </code></pre>
  
  <p><strong>NPR RSS Feed</strong></p>
  
  <pre><code>// is returning 'guid' as a string
  "item" : 
  [
      {
        // omitted other fields for brevity
        "guid" : "http:\/\/www.npr.org\/sections\/thetwo-way\/2015\/07\/31\/428188125\/chimps-in-habeas-corpus-case-will-no-longer-be-used-for-research?utm_medium=RSS&amp;utm_campaign=news"
      },
      {
        // ...
      }
  ]
  </code></pre>
  
  <hr>
  
  <p>I'm modeling this in Java like this:</p>
  
  <pre><code>// RSSFeedItem.java
  private Guid guid;
  
  // GUID.java
  private boolean isPermalink;
  private String content;
  </code></pre>
  
  <hr>
  
  <p>So in this case, it works perfectly fine calling</p>
  
  <pre><code>Gson gson = new Gson();
  RssFeed rssFeed = gson.fromJson(jsonData, RssFeed.class);
  </code></pre>
  
  <p>for the <strong>BBC RSS</strong> feed, but it throws an exception when parsing the <strong>NPR RSS</strong> feed.</p>
  
  <p>The specific error that led me to the conclusion that this is a type error was the following (when trying to deserialize the <strong>NPR RSS</strong> feed):</p>
  
  <pre><code>Severe:    com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
             Expected BEGIN_OBJECT but was STRING at line 1 column 673 path
             $.rss.channel.item[0].guid
  </code></pre>
  
  <hr>
  
  <p>So anyway, to the point: <strong>how can I handle this situation with Gson, where a field is being returned as potentially different data types?</strong> I'm guessing there might be some sort of trick or annotation I could use to this effect, but I'm not certain and after checking the documentation for Gson I couldn't find a readily available answer.</p>