title: How to handle Jackson InvalidFormatException gracefully?
body: <p>I'm currently struggling with Java JSON deserialization with Jackson in the following way:</p>
  
  <p>I want to process and deserialize a JSON response I get back from a webservice and convert the response into POJOs with the help of Jackson. This works fine most of the time, as long as the response I'm getting contains JSON attributes in the correct format.</p>
  
  <p>As however the webservice and the delivered data is <strong>out of my control</strong>, I can not rely on the data always being in the correct format.</p>
  
  <p>Let me give you an example:</p>
  
  <p>In my POJO, there's a <code>java.util.Date</code> field, and the JSON response contains a property holding a datetime string. Jackson will try to parse the string and convert it into a <code>Date</code>. If the date format matches the <code>ObjectMapper's</code> dateformat (<code>ObjectMapper.setDateFormat(...)</code>), everything is fine. If the format is different, I get an <code>InvalidFormatException</code>.</p>
  
  <p>The problem now is, the dateformat sent from the service <strong>can differ</strong>. I can get dates formatted like <code>2014-11-02T00:00:00Z</code>, but I can also get dates formatted like <code>2014-11</code> (identifying just a single month instead of an entire datetime).</p>
  
  <p>I know, I can write a custom deserializer which could take care of this exact case and handle datestrings with different date formats correctly. But as this would only fix issues with <code>Dates</code>, but not with potential other datatypes, I'm searching for a more general approach.
  (What happens e.g. if I expect a Double and receive an alphanumerical string?)</p>
  
  <p>What I would like is to have the possibility to ignore all cases in which an <code>InvalidFormatException</code> happens and define a default value (like <code>null</code>) to the respective POJO field. </p>
  
  <p>And it would be really valuable for me, if despite an invalid dateformat being returned or any other <code>InvalidFormatException</code> happening, the <strong>rest of the JSON</strong> would <strong>still be deserialized</strong> into the POJO.</p>
  
  <p>Is this in any way possible with Jackson?</p>
  
  <p>Thank you for reading my question till the end and I would be grateful for any pointers in the right direction.</p>