title: Handling "Unrecognized token" exception in custom json with Jackson
body: <p>I'm trying to use the Jackson json parser(v2.5.2) to parse a custom json document that isn't true json and I can't figure out how to make it work.  I have a json document that might look like:</p>
  
  <pre><code>{
      "test": {
          "one":"oneThing",
          "two": nonStandardThing(),
          "three": true
      }
  }
  </code></pre>
  
  <p>I want to use the ObjectMapper to map this to a <code>java.util.Map</code> and I would just like the <code>nonStandardThing()</code> to be added as a String value in my map for the key <code>two</code>.</p>
  
  <p>When I run this through the <code>ObjectMapper.readValue(json, Map.class)</code> I get the exception:</p>
  
  <pre><code>com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'nonStandardThing': was expecting 'null', 'true', 'false' or NaN
   at [Source: { "test":{"test1":nonStandardThing(),"test2":"two"}}; line: 1, column: 35]
      at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1487)
      at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:518)
      at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2300)
      at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2277)
  </code></pre>
  
  <p>I have tried to register a <code>DeserializationProblemHandler</code> with the <code>ObjectMapper</code> but it is never called when this problem occurs.  </p>
  
  <p>Here is sample application that shows what I have tried:</p>
  
  <pre><code>import com.fasterxml.jackson.core.JsonParser;
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.DeserializationContext;
  import com.fasterxml.jackson.databind.JsonDeserializer;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
  import java.io.IOException;
  import java.util.Map;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class JacksonDeserializerTest {
      private Logger log = Logger.getLogger(JacksonDeserializerTest.class.getName());
      public JacksonDeserializerTest() {
          String validJson = "{ \"test\":{\"test1\":\"one\",\"test2\":\"two\"}}";
          String invalidJson = "{ \"test\":{\"test1\":nonStandardThing(),\"test2\":\"two\"}}";
  
          ObjectMapper mapper = new ObjectMapper();
          mapper.addHandler(new DeserializationProblemHandler() {
              @Override
              public boolean handleUnknownProperty(DeserializationContext dc, JsonParser jp, JsonDeserializer&lt;?&gt; jd, Object bean, String property) throws IOException, JsonProcessingException {
                  System.out.println("Handling unknown property: " + property);
                  return false;
              }
          });
  
          try {
              log.log(Level.INFO, "Valid json looks like: {0}", mapper.readValue( validJson, Map.class).toString());
              log.log(Level.INFO, "Invalid json looks like: {0}", mapper.readValue(invalidJson, Map.class).toString());
          } catch (IOException ex) {
              log.log(Level.SEVERE, "Error parsing json", ex);
          }
  
      }
  
      public static void main(String[] args) {
          JacksonDeserializerTest test = new JacksonDeserializerTest();
      }
  }
  </code></pre>
  
  <p>The output looks like:</p>
  
  <pre><code>Apr 24, 2015 1:40:27 PM net.acesinc.data.json.generator.jackson.JacksonDeserializerTest &lt;init&gt;
  INFO: Valid json looks like: {test={test1=one, test2=two}}
  Apr 24, 2015 1:40:27 PM net.acesinc.data.json.generator.jackson.JacksonDeserializerTest &lt;init&gt;
  SEVERE: Error parsing json
  com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'nonStandardThing': was expecting 'null', 'true', 'false' or NaN
   at [Source: { "test":{"test1":nonStandardThing(),"test2":"two"}}; line: 1, column: 35]
      at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1487)
      at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:518)
      at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2300)
      at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2277)
      at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._matchToken(ReaderBasedJsonParser.java:2129)
  </code></pre>
  
  <p>Can anyone point out why the Handler never gets called?  Or, if there is a better parse this custom json document (jackson or not...), let me know. </p>